اسئلة واجب c++ مادة برمجة2 cs141


واجب عملي لمادة برمجة2  جامعة الامام محمد بن سعود بالرياض

لغة c++

 

Exercise #1

Write c++ program that simulates a simple calculator . it reads two integers(x,y) and a character (op).

If a character is a + , the sum is printed ; if it is a - ,the difference is printed ; if it is a*,the product is printed ;

If it is a/,the quotient is printed; and if it is a % , the remainder is printed . use a switch statement.

-----------------------------------------------------------------------

Exercise #2

Write c++ program that reads 10 of numbers, then find the largest and the second largest.

-----------------------------------------------------------------------

Exercise #3

Dangling –else problem : rewrite the following code to produce the output shown. The only change allowed is the edition of brace .the modified code should have approbation indentation

If(y == 8 )

If(x == 5 )

Cout<<"@@@@@@"<

Else

Cout<<"######"<

Cout<<"$$$$$$"<

Cout<<"&&&&&&"<

a-assuming x=5 and y=8 the output is

@@@@@@

$$$$$$

&&&&&&

b- assuming x=5 and y=8 the output is

@@@@@@

c- assuming x=5 and y=8 the output is

@@@@@@

&&&&&&

d- assuming x=5 and y=7 the output is

######

$$$$$$

&&&&&&

-----------------------------------------------------------------------

problem #4

Write the program that solves quadratic equations .a quadratic equation is an equation of the form (ax2+bx+c=0) , where a ,b and c are given coefficients and x is the unknown :

_ first , you should get values for the coefficients a, b, and c to calculate the discriminate (d) d=b2 - 4*a*c.

_if (d is less than zero ), there is no solution for the equation and print "there is no root".

_if (d is equal to zero ), there is one real solution (x1= -b/(2*a)).

_if (d is greater than zero ), there are two real roots :

X1=(-b+ sqr t(d))/(2*a)

X2=(-b- sqrt(d))/(2*a)

-----------------------------------------------------------------------

problem #5

Write c++ program that reads an integer value n (33>n>0), then prints a series of terms as following :

_the first term should be the value of n

_if the current term=1 the iteration will stop.

_if the current term is (even number ),the next term=current term/2

_if the current term is (odd number ),the next term=1+current term*3

Enter the value of n (0

The result of series where n=6 is :

6,3,10,5,16,8,4,2,1


المرفقات:
هل كان المحتوى مفيد؟

التعليقات

لاضافة سؤال أو تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول

محتاج مساعدة؟ تواصل مع مدرس اونلاين الان!

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...