a)initializing variable Pi with the value 3.14 (constant)
//declare
float Pi-3.14
b)declare a variable named parameter with double data type (declare variable)
//declare parameter
double parameter=5.776198
c)give instruction that alowed user to input data (input)
//input
cout<<"Enter data=";
cin>>data;
d)input number of computer using variable(input assign to variable value)
//declare nc=number of computer
intnc;
//input
cout<<"Enter number of computer=";
cin>>nc;
2. solve the question below.show the working
a) 5*2 %3 + 25 / 5
=[10%3]+25/5
=1+5
=6
b)a=5,b=6
!((a<3)&&(a==3)||(b>9))
=![(0)&&(0)||(0)|
=1
!((a<3)&&(a==3)| |(b>9))
3. identify syntax errors in the following program.
4. write a program that will calculate the monthly salary for an employee that where saturday and sunday are considered as non-working days.
5. write a program that calculates the average of 5 number that can be input by user
6. write a program thatwill calculate the area of rectangular,triangle and circle
#include <iostream.h>
main()
{
//declare
float b,h,r,w,area,;
float pi=3.14;
int selection;
//out
cout<<"Please choose you choice"<<endl;
cout<<"1.Rectangular";
cout<<"\n2.Triangle";
cout<<"\n3.Circle"<<endl;
cin>>selection;
switch (selection)
{
case 1: cout<<"Please input the height"<<endl;
cin>>h;
cout<<"Please input the width"<<endl;
cin>>w;
//process
area = w*h;
cout<<"The area is:"<<area;
break;
case 2: cout<<"Please input the height"<<endl;
cin>>h;
cout<<"Please input the base"<<endl;
cin>>b;
//process
area = 0.5*b*h;
cout<<"The area is:"<<area;
break;
case 3: cout<<"Please input the radius"<<endl;
cin>>r;
//process
area = pi*r*r;
cout<<"The area is:"<<area;
break;
default :cout<<"Invalid Selection";
return 0;
main()
{
//declare
float b,h,r,w,area,;
float pi=3.14;
int selection;
//out
cout<<"Please choose you choice"<<endl;
cout<<"1.Rectangular";
cout<<"\n2.Triangle";
cout<<"\n3.Circle"<<endl;
cin>>selection;
switch (selection)
{
case 1: cout<<"Please input the height"<<endl;
cin>>h;
cout<<"Please input the width"<<endl;
cin>>w;
//process
area = w*h;
cout<<"The area is:"<<area;
break;
case 2: cout<<"Please input the height"<<endl;
cin>>h;
cout<<"Please input the base"<<endl;
cin>>b;
//process
area = 0.5*b*h;
cout<<"The area is:"<<area;
break;
case 3: cout<<"Please input the radius"<<endl;
cin>>r;
//process
area = pi*r*r;
cout<<"The area is:"<<area;
break;
default :cout<<"Invalid Selection";
return 0;
}
No comments:
Post a Comment