Docsity

Exercise Solutions for Computer Programming (CS1121) - Mohammad Ali Jinnah University, Exercises of Computer Engineering and Programming

Toggle sidebar
bg1
Mohammad Ali Jinnah University, Islamabad Campus
Computer Programming (Lab) (CS1121)
Exercise 1
Instructor: Quratulain Siddiqui
Note: create a new project and execute the following code, try to solve the errors
yourself.
Q1. Identify (if any) error(s) found in the given code & write correct solution in .cpp file.
a. void Main (){
int a=0, Sum=0, b=w;
Sum= a+b;
}
b. float main ()
{
int a, b;
cin<<a;
float product;
product= a*b;
return product;
}
c. void main ()
{
bool 12xyz =false;
if (12xyz==false)
cout<<”the output is true” ;<< 12xyz;
}
d. void main(){
float dim=0.1, dum=0.9;
while ((dim+dum)==1)
{ count<<” DIM DUM”<< “\n” ;}
}
Q2: what will be the output of the following programs? Explain steps in comments.
a. void main (){
int a=0,b=0;
cin>> a;
cin>>b;
if(a<=b)
cout<<”Hello”;
else
cout<<”World”;
}
b. int main ()
{
int X=8, Y=1,Z=0;
While(Y!>10){
Z=X*Y; Y++;
cout<<X<<” *”<<Y<<” =”<<Z;
}
return 0;
}
c. void main (){
char alphabet=’b’;
bool guess=false;
if (alphabet ==’d’)
{guess =true; }
else
{guess =false; }
cout<< “Your Guess is ” << guess;
}
d. void main(){
char alpha=’y’;
while(alpha!=’n’){
cout<<”in Loop aphla = ”<< alpha;
cout<<”do you want to continue?
(y/n)”;
cin>>alpha;
}
cout<<”out of Loop alpha= ”<<alpha;
}
docsity.com

Partial preview of the text

Download Exercise Solutions for Computer Programming (CS1121) - Mohammad Ali Jinnah University and more Exercises Computer Engineering and Programming in PDF only on Docsity!

Mohammad Ali Jinnah University, Islamabad Campus

Computer Programming (Lab) (CS1121) Exercise 1 Instructor: Quratulain Siddiqui Note: create a new project and execute the following code, try to solve the errors yourself.

Q1. Identify (if any) error(s) found in the given code & write correct solution in .cpp file.

a. void Main () {

int a=0, Sum=0, b=w;

Sum= a+b;

b. float main () { int a, b; cin<<a; float product; product= a*b; return product; }

c. void main () { bool 12xyz =false; if (12xyz==false) cout<<”the output is true” ;<< 12xyz; } d. void main() { float dim=0.1, dum=0.9; while ((dim+dum)==1) { count<<” DIM DUM”<< “\n” ;} }

Q2: what will be the output of the following programs? Explain steps in comments.

a. void main (){

int a=0,b=0;

cin>> a;

cin>>b;

if(a<=b)

cout<<”Hello”;

else

cout<<”World”;

b. int main () { int X=8, Y=1,Z=0; While(Y!>10){ Z=X*Y; Y++; cout<<X<<” *”<<Y<<” =”<<Z; } return 0; }

c. void main (){ char alphabet=’b’; bool guess=false; if (alphabet ==’d’) {guess =true; } else {guess =false; } cout<< “Your Guess is ” << guess; } d. void main(){ char alpha=’y’; while(alpha!=’n’){ cout<<”in Loop aphla = ”<< alpha; cout<<”do you want to continue? (y/n)”; cin>>alpha; } cout<<”out of Loop alpha= ”<<alpha; }

docsity.com