0% found this document useful (0 votes)
26 views2 pages

Midterm 2021-2022 - Sol

C++ Exam

Uploaded by

kerolesmichael1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Midterm 2021-2022 - Sol

C++ Exam

Uploaded by

kerolesmichael1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

College of Computers and Informatics Midterm Exam [1M] x1 = -b + sqrt(D) / (2 * a));

Academic Year: 2021/2022


Subject Name: Computer Programming I [1M] x2 = -b - sqrt(D) / (2 * a));
Code: CS 101
Department: Computer Science cout<<"First root " << x1<<endl;
Date: Nov 2021 cout<<"Second root " << x2<<endl;
Time: 1 hrs
No. of Pages: 2
[1M] }else if( D == 0 ){
Full Mark: 20

Student Name: [1M] x1 = -b / ( 2 * a);

cout<<"Single Root " << x1 <<endl;


}else{
Q1) The following program computes the roots of quadratic
cout<<"Imaginary Roots" <<endl;
equation using the general following formula
}
√ return 0;
}
The roots may be two roots, single root or imaginary roots according to the Q2) Assume you have a 4-digit number and you want to reverse it in one
sign of the discriminator [ D = ]. The following program reads three equation, please complete the following to accomplish the reverse task.
values of a,b and c. Then it computes the roots if exists. Please complete the
missing lines so that the program functions correctly. #include <iostream>
using namespace std;
#include <iostream> int main()
[1M] #include <cmath> {
int x = 3245;
using namespace std;
int main() int r = x%10 + x/10%10*10+ x/100%10*100
{ [1M]
+ x/100%10*1000;
double a,b,c; cout<< “the reverse is “ << r << endl;
double x1,x2 ; return 0;
cout<<"Enter values of a,b and c: "; }
cin>>a>>b>>c;

[1M] double D = b*b – 4 * a * c ; Q3) Counting digit couples program counts how many two-digit neighbors
with the same value. For example, the number 113455567 would count 3.
[1M] if( D > 0 ){ This is because 11 , 55 and the second 55 are neighbors with the same digit.
Please complete the following program to complete the task.
#include<iostream>
using namespace std; Q5) Draw a flowchart for the following programs

int main(){ Program Flowchart


int x;
int count = 0; S1
int d1,d2; do
{
cin>>x; S2
while(x > 9){
[1M] while(C1)
[1M] d1 = x%10 ; S3

[1M] x = x/10 ; [1M] if(! C2)


S4
[1M] d2 = x%10 ;
S5
[1M] if( ){ }while(C3)
S6
count++;
}
}
Q6) Find the output of the following C++ statements
cout<< count <<endl;
[1M] for(int i=1;++i <=5 ; ) 2 3 4 5
return 0;
cout<< i ;
}
[1M] for(int i=1; i++ <=5 ; ) 2 3 4 5 6
Q4) Write a single condition for that combines all the following sub-
cout<< i ;
conditions for x [1M] for(int i=1;++i <=5 ; ) 3 5
• X is divided by 5 cout<< ++i ;
• X is not divided 20 [1M] for(int i=1; ; i++ ){ 1 2 4 5 7 8 10
• X is divided by 100 if(i % 3 == 0)
continue;
if(i % 11 == 0)
[2M] bool result = break;
(x%5==0 && x%20!=0)||(x%100==0); cout<< i ;
}
With my best wishes Dr. Amr Abdellatif

You might also like