Write a C++ program to accept percentage and print division accordingly.

Q22. Write a C++ program to accept percentage and print division accordingly.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int per;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter the percentage: “;

cin>>per;

 

per>=60? cout<<“\n I Division.” : per<60&&per>=45? cout<<“\n II Division.” :per>=36? cout<<“\n III Division.” : cout<<“\n Fail.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter the percentage: 78

 

I Division.

 

CASE 2:

Enter the percentage: 57

 

II Division.

 

CASE 3:

Enter the percentage: 33

 

Write a C++ program to accept a number and if it is less than 50 and greater than 20 than print its square value.

Q21. Write a C++ program to accept a number and if it is less than 50 and greater than 20 than print its square value.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a<50&&a>20? cout<<“\n The square of number is “<<a*a<<“.” : cout<<“\n The number is “<<a<<“.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

 

OUTPUT:

CASE 1:

Enter a number: 45

 

The square of number is 2025.

 

CASE 2:

Enter a number: 78

 

The number is 78.

Write a C++ program to accept a number and if it is less than 10 then print its square value.

Q20. Write a C++ program to accept a number and if it is less than 10 then print its square value.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a<10? cout<<“\n The square of number is “<<a*a<<“.” : cout<<“\n The number is “<<a<<“.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

 

Enter a number: 9

 

The square of number is 81.

 

CASE 2:

Enter a number: 11

 

The number is 11.

 

Write a C++ program to accept a number and determine whether it is even or odd.

Q19. Write a C++ program to accept a number and determine whether it is even or odd.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a%2==0? cout<<“\n It is an even number.” : cout<<“\n It is an odd number.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter a number: 7

 

It is an odd number.

 

CASE 2:

Enter a number: 6

 

It is an even number.

Write a C++ program to accept a character and determine whether its number, alphabet or symbol.

Q18. Write a C++ program to accept a character and determine whether its number, alphabet or symbol.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

char a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter any character: “;

cin>>a;

 

a>=65&&a<=90||a>=97&&a<=122? cout<<“\n It is an alphabet.” : a>=48&&a<=57? cout<<“\n It is a number.” : cout<<“\n It is a symbol.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter any character: d

 

It is a alphabet.

 

 

CASE 2:

Enter any character: 3

 

It is a number.

 

CASE 3:

Enter any character: $

 

It is a symbol.

Write a C++ program to accept a character and determine whether it’s upper case or lower case.

Q17. Write a C++ program to accept a character and determine whether it’s upper case or lower case.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

char a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter any character: “;

cin>>a;

 

a>=90?cout<<“\n It is a lower case letter.” : cout<<“\n It is an upper case letter.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter any character: r

 

It is a lower case letter.

 

CASE 2:

Enter any character: R

 

It is an upper case letter.

Write a C++ program to input users age and display a message you can vote or cannot vote.

Q16. Write a C++ program to input users age and display a message you can vote or cannot vote.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int age;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter your age: “;

cin>>age;

 

age>=18?cout<<“\n You can vote.” : cout<<“\n You cannot vote.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter your age: 7

 

You cannot vote.

 

CASE 2:

Enter your age: 28

 

You can vote.

Write a C++ program to take input in three subjects Physics, Chemistry and Math’s and calculate the total and percentage.

Q15. Write a C++ program to take input in three subjects Physics, Chemistry and Math’s and calculate the total and percentage.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int Phy,Chem,Maths,total,per;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter the marks of Physics: “;

cin>>Phy;

cout<<“\n Enter the marks of Chemistry: “;

cin>>Chem;

cout<<“\n Enter the marks of Math’s: “;

cin>>Maths;

 

total=Phy+Chem+Maths;

per=total/3;

 

cout<<“\n Total= “<<total;

cout<<“\n Percentage= “<<per<<“%”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

Enter the marks of Physics: 78

Enter the marks of Chemistry: 89

Enter the marks of Math’s: 90

Total= 257

Percentage= 85%

Write a C++ program to make use of ternary operator/conditional operator.

Q14. Write a C++ program to make use of ternary operator/conditional operator.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a,b,c;

 

clrscr(); //for clearing the screen

 

a=10;

b=15;

 

c=a>b?a:b>a?a:b; //turnary operator

 

cout<<“\n The value of C is “<<c<<“.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

The value of C is 10.

Write a C++ program to make use of ternary operator/conditional operator.

Q13. Write a C++ program to make use of ternary operator/conditional operator.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a,b,c;

 

clrscr(); //for clearing the screen

 

a=10;

b=15;

 

c=a>b?a:b; //turnary operator

 

cout<<“\n The value of C is “<<c<<“.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

The value of C is 15.