# CE 204: HOMEWORK

Md. Ferdous Alam, Lecturer, Dept. of CE, BUET, Dhaka-1000. Note: Some programs are erroneous. Students should find those errors and understand.
 #include<iostream.h>

void main () { double number,credit,GPA; double sum=0,sum_2=0; char answer; input_number: cout<<"Number= ";cin>>number; if(number<0 || number>100) { cout<<"Invalid number input\n"; goto input_number; } input_credit: cout<<"Credit= ";cin>>credit; if(credit<=0 || credit>4) { cout<<"Invalid credit input\n"; goto input_credit; }

if(number<40 && number>=0) credit=0; else credit=credit;

if(number<=100 && number>=80)

sum+=4.0*credit; 1

else if(number<80 && number>=75) sum+=3.75*credit; else if(number<75 && number>=70) sum+=3.5*credit; else if(number<70 && number>=65) sum+=3.25*credit; else if(number<65 && number>=60) sum+=3.0*credit; else if(number<60 && number>=55) sum+=2.75*credit; else if(number<55 && number>=50) sum+=2.5*credit; else if(number<50 && number>=45) sum+=2.25*credit; else if(number<45 && number>=40) sum+=2.0*credit; else sum+=0*credit;

#include<iostream.h>

int a=20; void main () {
2

cout<<a<<endl; int a=50; { int a=100; { int a=80; } cout<<a<<endl; } cout<<a<<endl; }  #include<iostream>

using namespace std; char main () { const int a=60; cin>>a; cout<<a<<endl; return 0; }  #include<iostream.h>

void main () { int a=b=10; cout<<a<<"\t"<<b<<endl; }

3

#include<iostream>

using namespace std; int main () { int a=10,b=20,c=30,d=40,e=50; a*=b/=c+=d-=e%=9; cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl; return 0; }  #include<iostream.h>

void main () { bool a=-50; a*=100; cout<<a<<endl; }  #include<iostream.h>

void main () { cout<<"\t\"Bangladesh is beautiful\"\n"; cout<<"Bangladesh University of Engineering and Technology"; cout<<"\n\t\tDhaka-1000"<<endl<<endl; cout<<'\t'<<'\t'<<"Civil Dept."<<'\n'<<'\n'; }  #include<iostream.h>

void main () {
4

int a='y'; cout<<a<<endl; char b=121; cout<<b<<endl; int c; c=a+b; cout<<c<<endl; char d; d=b-20; cout<<d<<endl; char e; e=a-20; cout<<e<<endl; }  #include<iostream.h>

void main () { char a; cin>>a; //input a=B;input a=other than A,B,C; switch(a){ case 'A': cout<<"One"<<endl; cout<<"One_1"<<endl; cout<<"One_One"<<endl;break; case 'B': cout<<"Two"<<endl; cout<<"Two_2"<<endl;
5

cout<<"Two_Two"<<endl;break; case 'C': cout<<"Three"<<endl; cout<<"Three_3"<<endl; cout<<"Three_Three"<<endl;break; default: cout<<"Sorry\n"; } }  #include<iostream.h>

void main () { char a; cin>>a; //input a=other than A,B,C; switch(a){ default: cout<<"Sorry\n"; case 'A': cout<<"One"<<endl; cout<<"One_1"<<endl; cout<<"One_One"<<endl;break; case 'B': cout<<"Two"<<endl; cout<<"Two_2"<<endl; cout<<"Two_Two"<<endl;break; case 'C': cout<<"Three"<<endl;
6

cout<<"Three_3"<<endl; cout<<"Three_Three"<<endl;break; } }  #include<iostream.h>

void main () { char a; cin>>a; //input a=other than A,B,C; switch(a){ default: cout<<"Sorry\n";break; case 'A': cout<<"One"<<endl; cout<<"One_1"<<endl; cout<<"One_One"<<endl;break; case 'B': cout<<"Two"<<endl; cout<<"Two_2"<<endl; cout<<"Two_Two"<<endl;break; case 'C': cout<<"Three"<<endl; cout<<"Three_3"<<endl; cout<<"Three_Three"<<endl;break; } }

7

#include<iostream.h>

void main () { char a; cin>>a; //input a=B; switch(a){ case 'A': cout<<"One"<<endl; cout<<"One_1"<<endl;break; cout<<"One_One"<<endl; case 'B': cout<<"Two"<<endl; cout<<"Two_2"<<endl;break; cout<<"Two_Two"<<endl; case 'C': cout<<"Three"<<endl; cout<<"Three_3"<<endl;break; cout<<"Three_Three"<<endl; default: cout<<"Sorry\n"; } }  #include<iostream.h>

void main () { char a; cin>>a; //input a=B;
8

switch(a){ case 'A': cout<<"One"<<endl; cout<<"One_1"<<endl;break; cout<<"One_One"<<endl; case 'B': cout<<"Two"<<endl; cout<<"Two_2"<<endl; cout<<"Two_Two"<<endl; case 'C': cout<<"Three"<<endl; cout<<"Three_3"<<endl;break; cout<<"Three_Three"<<endl; default: cout<<"Sorry\n";

} }  #include<iostream.h>

void main () { cout<<true<<endl; cout<<false<<endl; cout<<endl; float a=10,b=20; cout<<(a=10)<<endl <<(a==10)<<endl
9

<<(a=b)<<endl <<(a==b)<<endl <<(a>b)<<endl <<(a>=b)<<endl <<(a<=b)<<endl <<(a<b)<<endl <<!(a<b)<<endl <<!(b==20)<<endl <<(a<b && b==30)<<endl <<(a<b || b==30)<<endl; float x=50,y=60,z=70; cout<<(x==50 && y>x && z<y)<<endl <<(x==50 || y>x && z<y)<<endl <<(x>y && y>z || z>x)<<endl <<(x>y && y>z && z<40 || x+y>z*y)<<endl <<(x>y && y>z && z<40 || (x+y)>(z*y))<<endl; }  #include<iostream>

using namespace std; double main () { double number; cin>>number;//input number=62;we are assuming 0<=number<=100; if(number<=100 && number>=80) cout<<"A+\n"; if(number<80 && number>=75) if(number<75 && number>=70) if(number<70 && number>=65) cout<<"A\n"; cout<<"A-\n"; cout<<"B+\n";
10

if(number<65 && number>=60) if(number<60 && number>=55) if(number<55 && number>=50) if(number<50 && number>=45) if(number<45 && number>=40) if(number<40 && number>=0)

cout<<"B\n"; cout<<"B-\n"; cout<<"C+\n"; cout<<"C\n"; cout<<"D\n"; cout<<"F\n";

return 0; }  #include<iostream>

using namespace std; double main () { double number; cin>>number;//input number=62;we are assuming 0<=number<=100; if(number>=80) cout<<"A+\n"; if(number>=75) cout<<"A\n"; if(number>=70) cout<<"A-\n"; if(number>=65) cout<<"B+\n"; if(number>=60) cout<<"B\n"; if(number>=55) cout<<"B-\n"; if(number>=50) cout<<"C+\n"; if(number>=45) cout<<"C\n"; if(number>=40) cout<<"D\n"; if(number<40) cout<<"F\n";

return 0;
11

}  #include<iostream>

using namespace std; double main () { double number; cin>>number;////input number=62;we are assuming 0<=number<=100; if(number>=80) cout<<"A+\n";

else if(number>=75) cout<<"A\n"; else if(number>=70) cout<<"A-\n"; else if(number>=65) cout<<"B+\n"; else if(number>=60) cout<<"B\n"; else if(number>=55) cout<<"B-\n"; else if(number>=50) cout<<"C+\n"; else if(number>=45) cout<<"C\n"; else if(number>=40) cout<<"D\n"; else cout<<"F\n";

return 0; }

#include<iostream.h>

void main () { double number_1=20,number_2; number_2=100+number_1++;
12

cout<<number_2<<endl; cout<<number_1<<endl;

double a=20,b; b=100 + ++a; cout<<b<<endl; cout<<a<<endl;

double number_3=20,number_4; number_4=100+number_3--; cout<<number_4<<endl; cout<<number_3<<endl;

double c=20,d; d=100 + --c; cout<<d<<endl; cout<<c<<endl;

}  #include<iostream.h>

void main () { float a=100,b=200,c,d,e; c=a+ b++; d=b+ a--; e=a- --b; cout<<c<<"\t"<<d<<"\t"<<e<<endl;
13

}  #include<iostream.h>

void main () { int a,b,c; cin>>a>>b>>c;//assuming a‡b‡c; if(a<b) { if(a<c) { cout<<"a is the minimum\n"; } else { cout<<"c is the minimum\n"; } } else { if(b<c) { cout<<"b is the minimum\n"; } else { cout<<"c is the minimum\n"; }
14

} }  #include<iostream.h>

void main () { int b=800; char a; cin>>a; if(a=='h') { int a=20,b; b=a+10; } else if(a=='r') { int a=30,b; b=a*2; } else { int a=40,b; b=100+a; } cout<<b<<endl; }  #include<iostream.h>

void main ()
15

{ char a; cin>>a; if(a=='h') { int a=20,b; b=a+10; } else if(a=='r') { int a=30,b; b=a*2; } else { int a=40,b; b=100+a; } cout<<b<<endl; }

#include<iostream.h>

void main () { int b=800; char a;
16

cin>>a; if(a=='h') { int a; a=b+10; cout<<a<<endl; } else if(a=='r') { int a; a=b*2; cout<<a<<endl; } else { int a; a=100+b; cout<<a<<endl; } }

#include<iostream.h>

void main () { double a; cin>>a;//input a=any value; if(a=10)
17

{ cout<<"Excellent\n"; } else { cout<<"Confused\n"; } }  #include<iostream.h>

void main () { double a; cin>>a;//input a=10 and then a=other than 10; if(a==10) { cout<<"Excellent\n"; } else { cout<<"Confused\n"; } }

#include<iostream.h>

void main () { double a; cin>>a;//input a=any value; if(1)
18

{ cout<<"Excellent\n"; } else { cout<<"Confused\n"; } }  #include<iostream.h>

void main () { double a; cin>>a;//input a=any value; if(true) { cout<<"Excellent\n"; } else { cout<<"Confused\n"; } }

#include<iostream.h>

void main () { double a; cin>>a;//input a=0; if(a)
19

{ cout<<"Excellent\n"; } else { cout<<"Confused\n"; } }  #include<iostream.h>

civil: cout<<"Length of the beam (ft)= "; cin>>beam_length; if(beam_length<=0) { cout<<"Invalid input\n"; goto civil; } cout<<"Value of the point load (kip) (downward positive)= "; cin>>point_load_value; buet:
20

cout<<"R1= "<<R1<<" kip\n"; cout<<"R2= "<<R2<<" kip\n"; }  #include<iostream.h>

void main () { double a; cin>>a; switch(a){ case 50: cout<<"Fifty\n";break; case 20: cout<<"Twenty\n";break; case 60: cout<<"Sixty\n";break; default: cout<<"Sorry\n";
21

} }  #include<iostream.h>

void main () { int a=10; { int a=10; a++; } cout<<a<<endl; }  #include<iostream.h>

void main () { int a=10; { a++; } cout<<a<<endl; }  #include<iostream.h>

void main () { int choice; line1:cout<<"Choice= "; cin>>choice;
22

switch(choice){ case 4: int a,b,c; cout<<"a= "; cin>>a; cout<<"b= "; cin>>b; c=a+b; switch(c){ case 50: cout<<"Half century\n";break; default: cout<<"Out of range\n"; } break; case 2: int x,y,z; cout<<"x= "; cin>>x; cout<<"y= "; cin>>y; z=(x-y); if(z==100) { cout<<"Century\n"; } else cout<<"Out of range\n";break; default: goto line1; } }
23

#include<iostream.h> //Program of 1+2+3+4+……………………+n;

void main () { int a; cin>>a; int m=1; int sum=0; calculate: sum+=m; m++; if(m<=a) goto calculate; else goto end; end: cout<<"Sum= "<<sum<<endl; }

   

Write a program to find the minimum of 5 numbers taken from the user. Write a program to swap two values taken from the user without using any 3rd variable. Write a program to determine whether a year is leap year or not. Write a program to determine the age of a student of BUET. The program will prompt for the date of birth of the student (date, month, and year) and the present time (date, month, and year).

 

Write a program to determine the summation of the following series:

Write a program to calculate the GPA of a student of BUET. The program will prompt for marks in various subjects. (Hint: use goto statement)

BEST OF LUCK
24