Professional Documents
Culture Documents
Cplab 3
Cplab 3
Cplab 3
Rizwan
Wasim
EE123107
[ASSIGNMENT # 3]
Computer lab assignment # 3
Q1. Determine the value of the following expressions:
Ans 1.1: 10 + 17 / 3. + 4
By applying DMAS rule we can determine the value of given expression, first we divide 17 / 3 which is
equal to 5.667, now add the whole expression which is 10+5.667+4 = 19.667
In this expression first we solve the expression in round brackets , add m+n and p+amount then
perform division between answers of m+n and p+amount
In this expression we use DMAS rule to solve it, fisrt we divide 4 by 6 which is equal to = 0.667
then we multiply 0.667 with 3.0 which is equal to = 2.001 now add it with 6.
The answer of whole expression is 8.001
Q2. Write a C++ program to calculate and display the combined resistance when
the three resistors R1 = 1000, R2 = 1000, and R3 = 1000 are connected in parallel.
# include <iostream>
Int main ()
R1=R2=R3=1000.00 ;
Rn =(1/R1+1/R2+1/R3) ;
Return 0 ;
Q3. For a = 10.6, b = 13.9 and c = -3.42, determine the following values:
3.2 int (a + b + c)
Ans: As the value of a, b and c are in floating points values or in decimal form values , if we put
these values in above given statement of C++ its gives us result in real numbers but not in
floating points or in decimal form as the answer the is in decimals.
int (a+b+c) = int (10.6+13.9+(-3.42))
int (10.6+13.9+(-3.42)) = int (10.6 + 13.9 - 3.42)
int (10.6 + 13.9 - 3.42) = int (21.08)
int (21.08) = 21
Q4. Write a program which performs subtraction of two numbers using bitwise
operators.
Q5. You are given following variables:
char key = 'm';
int i = 5, j = 7, k = 12;
double x = 22.5;
Display result of expressions:
Q6. A student’s letter grade is calculated according to the following schedule:
# include <iostream>
using mainspace std ;
int main ()
{
Constant float max_marks=90.0F ;
float marks_obtained ;
cout<<”enter a value of marks obtained “ ;
cin>>marks_obtained;
int percentage = int (mark_obtained/max_marks)*(100);
if (percentage >= 90);
cout<< ”Grade A”;
else if (percentage >= 80);
cout<< ”Grade B”;
else if (percentage >= 70);
cout<< “Grade C”;
else if (percentage >= 60);
cout<< “Grade D”;
else if (percentage < 60);
cout <<“Grade F”;
Return 0;
}
Q8. Write a program that takes a four digits integer from user and shows the digits
on the screen separately i-e if user enters 7531, program should display 7,5,3,1 or
1,3,5,7 (Hint: Use % Operator)
Q9. Write a program in C++ in which the user enters the number in integer and
then type cast it into string, float and character.
Q10. Write a program that prompts the user to enter two positive integers and then
tests whether the larger integer is exactly divisible by smaller one. In the process
you’ll need to check that the input values are both valid (greater than zero) and
then establish which of them is larger.