You are on page 1of 3

CLASSWORK APPLICATIONS FOR C++ DATA TYPES, OPERATORS &

INTRINSIC FUNCTIONS

Q1. Write a program to:


-Declare c1, c2, c3, c4 and c5 as char.
-Assign them to M, E, 2, 4, 0 respectively.
-Display ME240 using c1, c2, c3, c4 and c5.
Q2. Write the previous program using a single character string.
Q3. Write a program that calculates the area of a rectangle. The width and height of the
rectangle must be given using keyboard.

Q4. Without using a computer, find the output the following program;

#include <iostream>
using namespace std;

int main(){
int a(5),b(8);
cout<<"\ta=\t"<<a<<"--->b="<<b
<<"--->\n"<<a+b<<endl;

system ("pause");
}

Q5. Without using a computer, find the output the following program;

#include <iostream>
using namespace std;

int main(){
int a=5;
{
int a=7;
{
int a=12;
cout<<"\t"<<2*a;
}
cout<<"\t"<<2*a;
}
cout<<"\t"<<2*a;
system ("pause");
}
Q6. Correct the program given below that calculates the function for arbitrary values of x.

3
3/2

#include <iostream>
using namespace std; Sample Output

int main() { input x


double x,fx; 2
cout<<"input x\n"; fx =-14.6667
cin>>x;
fx=x/3-pow(x,3)/(x-3/2);
cout<<"fx ="<<fx
system ("pause");
}

Q7. Write C++ statements to evaluate the following algebraic formulae:

a+ b b a+ b
a) z = b) z = a + c) z = +d
c+d c+d c

a+ b
d) z =
d
c+
e+f

Q8. Find the result of the following arithmetic operation;

double( floor(5.2) / ceil(-2.7) ) + 5%2

Q9. Find the result of following operation.

abs(-2.3)/2+1.3*sqrt(4.)/double(5/2)

Q10. Find the result of each line int the following program section:

double x=10.0, y=0.01, z=0.5 ;


int i=10, j=25, k=3 ;
cout << ceil(j/x)+floor(x+j/2) ;
cout << z * x / 10 + k ;
cout << z * k + z * j + z * i ;
cout << i * y - k / x + j ;
Q11. Write a program to calculate the following function:

2
ln
3
where e is well known constant.

Q12. Write a program to obtain the following table for your friends:

Name Surname City Phone


Ali Can İstanbul 0 5?? ???????

Q13. To convert temperatures written in Fahrenheit to Celsius (Centigrade), you subtract 32,
multiply by 5 and then divide by 9. To convert Celsius to Absolute Value (Kelvin), you add
273.15. Write a program that converts a temperature given in Fahrenheit to
Celcius(Centigrade) and Absolute Value(Kelvin).

You might also like