Assignment 4: Write Output of The Following C++ Codes
Assignment 4: Write Output of The Following C++ Codes
(1)
void main( )
{
if((a>5) ||(b<=10)&&(c<15))
cout<<”Computer Science”;
else
cout<<”Software Engineering”;
(2)
void main( )
{
int choice = 2;
switch (choice)
{
case 0: cout<<”C++”;
case 1:
case 2: cout << "Less than 3";
case 3: cout << "Equals 3";
case 4: cout << "Greater than 3"; break;
}
}
(3)
void main( )
{
int a = 7, b = 9, c = 0;
if(a <= 7)
{
if(b>9)
cout<<”A \n”;
else
cout<<”B \n”;
}
else
if(c > -1)
cout<<”D \n”;
else
cout<<”E \n”;
(4)
void main( )
{
int a = 5;
int b = 6;
int c = 0;
c = 5 * a+b++;
if (c>30)
cout<<”a: “<<a<<”b: “<<b<<”c: “<<c;
else if (c<30)
{
int diff = (int) 5.5 % (int) 2.5;
cout<<”The value of diff=”<<diff;
}
else
{
b = 5 * a-c--;
cout<<”a: “<<a<<”b: “<<b<<”c: “<<c;
}
}
(5)
void main( )
{
int x = 5, y = 30;
if(y/x > 2)
if(y % x !=2)
x = x + 2;
cout<<x<<”\n“<<y;
}
(6)
void main( )
{
int a = 5, b = 30;
if(a > b)
if(b > 0)
a = a + 5;
else
if(b >= 30)
b = b * 10;
(7)
void main( )
{
int age=18;
if(age>14)
{
if(age>=18)
{
cout<<"Adult";
}
else
{
cout<<"Teenager";
}
}
else
{
if (age > 0)
{
cout<<"Child";
}
else
{
cout << "Something's wrong";
}
}
}
(8)
int main( )
{
int selection, rentaltype, time, week=0 , weekend, rent, hours;
char custom = 0 ;
cout << "enter hours , type , type simultaneously )" << endl;
cin >> hours >> time >> rentaltype ;
if ( rentaltype == custom )
{
if ( time == week )
{
if ( hours <= 3 )
{
rent = 25 ;
cout << " rent amount is : " << rent << endl ;
}
}
} else {
cout << " get out from my house " << endl ;
}
return 0 ;
}