This document contains a midterm examination for a course consisting of 3 questions worth a total of 40 marks. Question 1 (10 marks) asks to analyze and correct errors in a given C++ program. Question 2 (10 marks) asks to generate the output of some C++ code statements. Question 3 (20 marks) asks to design a complete C++ program to solve a given equation, calculate and display the value of Z, count values of Z between 0-2000, and ask the user to change iteration if Z is above 100,000.
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
Midterm cpp q_a_may_2014(2)
1. May-Aug 2014 Midterm Examination EE209/ED203
Instruction: Answer all THREE (3) questions
TOTAL: 40 Marks
Q1 Consider the following program. Analyze and correct the errors.
#include <iostream>
using namespace std;
int main(){
bool flag= true;
char name = 'a';
int i,j,k,l;
do{
for(i=-2;i<=0;i++){
for(j=-3;j<=i;j++){
k=i*2 -j;
if(abs(i+j)==1 || j==1){
cout<< "#";
}
else if(j==2 || i<k){
cout<< "+";
}
else{
cout<< j <<endl;
}
}
}
cout<<name;
name++;
if(name == 'c'){
flag = false;
}
else{
//no operation
}
}while(flag);
system("pause");
}
(10 marks)
2. May-Aug 2014 Midterm Examination EE209/ED203
Q2 Generate the output of the following statements.
#include <iostream>
using namespace std;
int main(){
bool flazz;
flazz = false;
char your ='C';
int i,j,k,l;
while(!flazz){
--your;
cout<<your;
if(your == 'A'){
flazz = true;
}
for(i=0;i>=-2;i--){
for(j=0;j>=i;j--){
k=i*2 -j;
if((i-j)==1 || i==1){
cout<<"#";
}
else{
cout<<j<<endl;
}
}
}
}
system("pause");
}
(10 marks)
Q3 Design a complete C++ program to solve the following equation.
iteration
n
nnZ
1
)5)(1(
If user entered “start”, start the program, while the user entered “stop”, end the
program. User must enter the value of iteration. Your program must calculate and display
the value of Z. If the value of Z between 0 to 2000, count and display the number of Z. If
the value of Z above 100000, your program must ask the user to change the iteration
value or stop the program. Use while loop, if else statement and boolean data type.
Answer
3. May-Aug 2014 Midterm Examination EE209/ED203
#include <iostream>
#include <string>
using namespace std;
int main(){
string user;
bool flag;
cout<<"enter <start> or <stop> ";
cin>>user;
if(user =="start"){
flag = true;
}
else if(user == "stop"){
flag = false;
goto done;
}
else{
//nop
}
again:
int iteration,n=1,equation,Z=0,c=0;
cout<<"enter your iteration ";
cin>>iteration;
while(flag && n<=iteration){
for(n=1; n<=iteration; n++){
equation = (n+1)*(n+5);
Z = Z + equation; //summation
cout<< Z <<endl;
if(Z>0 && Z<2000){
c++; //count
cout<<"the number of Z is "<< c <<endl;
}
else if(Z>100000){
goto again;
}
else{
//nop
}
}
}
done:
system("pause");