Cplab 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

2012

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

Ans 1.2: (m + n) / (p + amount)

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

Ans 1.3: 3.0 * 4 % 6 + 6

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.

Ans : program for finding combined resistance

# include <iostream>

Using mainspace std ;

Int main ()

Float R1, R2, R3 ;

R1=R2=R3=1000.00 ;

Rn =(1/R1+1/R2+1/R3) ;

Combined resistance = 1/(Rn) ;


Cout >> “combined resistance” ;

Return 0 ;

Q3. For a = 10.6, b = 13.9 and c = -3.42, determine the following values:

3.1 int (a)


Ans: As the value of a is 10.6 which is in decimal value or in floating points value , if we put
this value into above C++ statement its give us result in real number but not floating or in
decimal number as the answer is in floating point..
int (a)= int (10.6)=10

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

3.3 float (int (a + b))


Ans: As the value of a and b are in floating points values or in decimal form values , if we put
these values in above given statement of C++ its gives us following results:
1.we use half expression that is int (a+b)
int (a+b)=int (10.6+13.9) = int (24.5 ) = 24
2. we put the value of int(a+b) in remaining expression that is float (int (a+b))
flaot (int (a+b)) = float (24) = 24.00

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:

Ans: Program for students grade

# 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;
}

Q7. Make solution of quadratics equation in C++

Ans: Program make solution of quadratics equations


# include <iostream>
using mainspace std ;
int main ( )
{
int a, b, c, x1, x2 ;
cout << “enter the value of a, b,c as a,b,c > 1” ;
cin >> a >> b >>c ;
x1 = - b + (b*b – 4ac)/ 2a ;
x2 = - b – (b*b – 4ac)/ 2a ;
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.

You might also like