0% found this document useful (0 votes)
204 views3 pages

نسخة Midterm CSC 115 Spring 2020

The document is a midterm exam for a programming in C++ course containing 10 multiple choice questions testing concepts like loops, conditional statements, functions, and basic C++ programs. It asks students to write code to add numbers entered by the user until 0 is entered and output the total. The exam is worth 20 marks and covers topics taught in the course.
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)
204 views3 pages

نسخة Midterm CSC 115 Spring 2020

The document is a midterm exam for a programming in C++ course containing 10 multiple choice questions testing concepts like loops, conditional statements, functions, and basic C++ programs. It asks students to write code to add numbers entered by the user until 0 is entered and output the total. The exam is worth 20 marks and covers topics taught in the course.
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/ 3

king Saud University Midterm 1 Fall 2020

College of Computer and CSC 115-Programming in


Information Sciences C++
Computer science department 20 Marks

Question 1 (5 Marks)
a) 01 b) 1 c) 0 d) No output
Q1. What is the output of this program?
for(int i=0; i<5; i++)
{ if(i==3)
continue; Q5. What is the value of x if the value of y is 10 ?
cout<<i;
}
int main()
a) 0124 b) 1234 c) 01234 d) 3 {
Q2. What is the output of this program? int x=0,y=0;
int x=7; cout<<"Enter the value of y";
if(x==2); cin>>y;
cout<<"NumberSeven"; if(y>=10)
cout<<"NotSeven"; x=1;
cout<<x;
a) Error b) NotSeven c) NumberSeven Notseven }
d) NumberSeven
__________________________________________
a) 0 b) 1 c) no result d) wrong
Q3. What is the output of this program? input
#include <iostream>
using namespace std;
Q6. What is the output of the following question?
int main()
int main() {
{ int x=10,y=0;
int i = 0, j; if(x&&y)
switch( i ){ cout<<"True";
case 0: j = 0; else
cout<< j ; cout<<"False";
case 1: j = 1;
cout<< j ; }
case 2: j = 2;
cout<< j ; a) True b) False c) Compilation Error d)
runtime Error
break;
default: j = -1; Q7.
cout<< j; int main() {
int x = 3, y = 4;
}} } switch(x + 3){
case 6: y = 0;
a) 12-1 b) Compilation error c) 012 d) 1
case 7: y = 2;
Q4. What, if any, is the output of the following program? default: y += 1;
}
#include <iostream> cout<<y;
using namespace std;
}
int main(){
int m = 0; a) 5 b) 3 c) 1 d) 0
while(++m < 2)
cout<<m++;
}
king Saud University Midterm 1 Fall 2020
College of Computer and CSC 115-Programming in
Information Sciences C++
Computer science department 20 Marks

Question 2 (5 Marks)

Q8) How many times this program will


Write a program to print positive number
print “welcome to c++” ? entered by the user?
int main()
{
Output
int count = 1;
do { Enter an integer: 5
cout<<"Welcome to c++ "<<count<<endl; You entered a positive number: 5
count++; Enter an integer: -5
}while (count < 1); You entered a negative number:-5

a) 8 b) 9 c) 1 d) 10

Q9) Which of the following for loops will be an infinite loop?

A. for(; ;)
B. for(i=0 ; i<1; i--)
C. for(i=0; ; i++)
D. All of the above

a) A b) C c) All of the above d) A & C

Q10) what is the output for the following


program?
int main()
{
int i, j=1;
i = (j>1)?2:1;
switch(i){
case 0: cout<<0; break;
case 1: cout<<1;
case 2: cout<<2; break;
case 3: cout<<3; break;
}
}

a) 1 b) 2 c). 3 d) 1 2

Question 3(5 Marks):


Write a C++ program to add numbers until user enters 0?

Enter a number: 2
Enter a number: 3
king Saud University Midterm 1 Fall 2020
College of Computer and CSC 115-Programming in
Information Sciences C++
Computer science department 20 Marks

Enter a number: 4
Enter a number: -4
Enter a number: 2
Enter a number: 4.4
Enter a number: 2
Enter a number: 0

You might also like