0% found this document useful (0 votes)
14 views5 pages

If Sec2

This program calculates the gravitational force between two masses given their values and the distance between them. It prompts the user to input the mass of two objects in kg, and the distance between them in meters. It then calculates the gravitational force using the formula: F=G*(m1*m2)/(r^2), where G is the gravitational constant, m1 and m2 are the masses, and r is the distance. It prints the resulting gravitational force.

Uploaded by

yw89407
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)
14 views5 pages

If Sec2

This program calculates the gravitational force between two masses given their values and the distance between them. It prompts the user to input the mass of two objects in kg, and the distance between them in meters. It then calculates the gravitational force using the formula: F=G*(m1*m2)/(r^2), where G is the gravitational constant, m1 and m2 are the masses, and r is the distance. It prints the resulting gravitational force.

Uploaded by

yw89407
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/ 5

Ex5 : Write a program to calculate the gravitational force of two

masses. (Q7 sheet 3)

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long double m1,m2,r,G,F;
G=6.674*pow(10,-11);

cout<<"enter m1 in kg :\n ";


cin>>m1;
cout<<"enter m2 in kg :\n ";
cin>>m2;
cout<<"enter r in m :\n ";
cin>>r;
F=G*(m1*m2)/ (r*r);
cout<< "Gravitational force = "<<F<<"\n";
system("PAUSE");
}

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

You might also like