0% found this document useful (0 votes)
38 views

Assignment 4: Write Output of The Following C++ Codes

The document contains 8 code snippets in C++ and asks to write the output of each code. 1. The first code prints "Computer Science" as the condition (a>5) ||(b<=10)&&(c<15) is true. 2. The second code prints "Less than 3" as choice was given as 2 and there is no break after case 1. 3. The third code prints "B" as conditions a <= 7 and b>9 are satisfied. 4. The fourth code prints values of a, b, c with c=30 as output of c is 30 satisfying the if condition. 5. The fifth code prints 7 30 as

Uploaded by

gohib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Assignment 4: Write Output of The Following C++ Codes

The document contains 8 code snippets in C++ and asks to write the output of each code. 1. The first code prints "Computer Science" as the condition (a>5) ||(b<=10)&&(c<15) is true. 2. The second code prints "Less than 3" as choice was given as 2 and there is no break after case 1. 3. The third code prints "B" as conditions a <= 7 and b>9 are satisfied. 4. The fourth code prints values of a, b, c with c=30 as output of c is 30 satisfying the if condition. 5. The fifth code prints 7 30 as

Uploaded by

gohib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 4

Write output of the following C++ codes:

(1)

void main( )
{

int a = 5, b = 10, c = 15;

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;

int temp = (b<30)?b*2:b/2;


cout<<”a=”<<a<<” ”<<”b=”<<b;
}

(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 ;
}

You might also like