If Sec2
If Sec2
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long double m1,m2,r,G,F;
G=6.674*pow(10,-11);
1
EX6 : write a c++ program to read a number of the month and print the month
name in alphabetic . (Q9 sheet 3)
#include<iostream>
using namespace std ;
int main ()
{
int no;
cout<<"enter a number from 1-12 ";
cin>>no;
if (no==1)
cout<<"January \n";
else if (no==2)
cout<<"February \n ";
else if (no==3)
cout<<"March ";
else if (no==4)
cout<<"April ";
else if (no==5)
cout<<"May ";
else if (no==6)
cout<<"June ";
else if (no==7)
cout<<"July";
else if (no==8)
cout<<"August";
else if (no==9)
cout<<"September";
else if (no==10)
cout<<"October ";
else if (no==11)
cout<<"November";
else if (no==12)
cout<<"December";
else
cout<<" you enterd the wrong no. (1 to 12)";
system("pause");
}
2
Students will replace if by switch
#include<iostream>
using namespace std ;
int main ()
{
int no;
cout<<"enter a number from 1-12 ";
cin>>no;
switch(no){
case 1:cout<<"January \n";break;
case 2:cout<<"February \n ";break;
case 3:cout<<"March ";break;
case 4:cout<<"April\n ";break;
case 5:cout<<"May \n ";break;
case 6:cout<<"June\n ";break;
case 7:cout<<"July \n";break;
case 8:cout<<"August \n";break;
case 9:cout<<"September \n";break;
case 10:cout<<"October \n";break;
case 11:cout<<"November \n";break;
case 12:cout<<"December \n";break;
Default: cout<<" you enterd the wrong no. (1 to 12)";break;
}
system("pause");
}
3
EX7: Write a program that reads a character and then prints: “It is a vowel” if it is
a vowel, “It is an operator” if it is one of the five arithmetic operators, and “It is
something else” if it is anything else. (Q13 sheet 3)
#include <iostream>
using namespace std;
int main()
{ while (true) {
char x;
cin>>x;
if ((x=='i')||(x=='a')||(x=='e')||(x=='o')||(x=='u'))
cout<<"you had entered vowel letters "<<endl;
else if ((x=='+')||(x=='-')||(x=='%')||(x=='*')||(x=='/'))
cout<<"you had entered vowel an arithmetic operator"<<endl;
else
cout<<"enter vowel letters and arithmetic operator";
}
system("PAUSE");}
EX8: Write a program that reads the salary of each worker and print the net salary
after reducing the taxes according to the table below salary percentage of taxes %
1000 – 1500 %6
1501 – 2000 %7
2001 – 2500 %8
(Q12 sheet 3)
#include <iostream>
using namespace std;
int main()
{ while(true) {
float salary ;
cout<<"please Enter the salary : "<<endl;
cin>>salary;
if (salary<1000)
cout<<"no tax"<<endl;
if ((salary>=1000)&&(salary <=1500))
cout<<"the salary is 6% . and that = "<<salary*6/100<<endl;
if ((salary>1500)&&(salary <=2000))
cout<<"the salary is 7% . and that = "<<salary*7/100<<endl;
if ((salary>2000)&&(salary <=2500))
cout<<"the salary is 8% . and that = "<<salary*8/100<<endl;
else
cout<<"enter salary range between 0-2500"<<endl;
} system("PAUSE");}
4
5