Sunday, February 24, 2013

C++ Code Of If Else Statements 2


Any character is entered by the user; write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol.The following table shows the range of ASCII values for various characters.

Characters ASCII Values
A – Z 65 – 90
a – z 97 – 122
0 – 9 48 – 57
special symbols 0 - 47, 58 - 64, 91 - 96, 123 – 127



 

#include<iostream.h>
#include<conio.h>

int main ()
{
 char ch;
 cout<<"Enter any character:";
 cin>>ch;

 if (ch>=65 && ch<=90)
  cout<<"Character is a capital letter";
 else if (ch>=97 && ch<=122)
  cout<<"Character is a small letter";
 else if (ch>=48 && ch<=57)
  cout<<"Character is a digit";
 else if ((ch>0 && ch<=47)||(ch>=58 && ch<=64)||(ch>=91 && ch<=96)||(ch>=123 && ch<=127))
  cout<<"Character is a special symbol";

 getch();
 return 0;
}



**************************************************

Any character is entered by the user; write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol.The following table shows the range of ASCII values for various characters.




#include<iostream.h>
#include<conio.h>

int main()
{
 float basic_salary, gross_salary, HRA, DA;
 cout<<"Enter basic salary of Employee : ";
 cin>>basic_salary;

 if (basic_salary<1500)
 {
  HRA=0.1*basic_salary;
  DA=0.9*basic_salary;
 }
 else
 { 
  HRA=500;
  DA=0.98*basic_salary;
 }

 gross_salary=basic_salary+HRA+DA;
 cout<<"Gross salary is : "<<gross_salary;

 getch();
 return 0;
}


**************************************************


The marks obtained by a student in 5 different subjects are input by the user. The student gets a division as per the following rules:
Percentage above or equal to 60 - First division
Percentage between 50 and 59 - Second division
Percentage between 40 and 49 - Third division
Percentage less than 40 - Fail
Write a program to calculate the division obtained by the student.




 

#include<iostream.h>
#include<conio.h>

int main()
{
 int sub1,sub2,sub3,sub4,sub5,percentage;
 cout<<"Enter marks of five subjects : ";
 cin>>sub1>>sub2>>sub3>>sub4>>sub5;
 percentage=(sub1+sub2+sub3+sub4+sub5)/5;

 if(percentage>=60)
  cout<<"Ist division";
 else if(percentage>=50)
  cout<<"IInd division";
 else if(percentage>=40)
  cout<<"IIIrd division";
 else
  cout<<"Fail" ;

 getch();
 return 0;
}



No comments:

Post a Comment