代写 C algorithm UNIVERSITY OF MACAU

UNIVERSITY OF MACAU
FACULTY OF BUSINESS ADMINISTRATION
ISOM 3029 Computer Programming Using C
Midterm Examination
Fall Semester 20192020
Time allowed: 1.5 hours

Instructions:
Please write down your Student Name, Student ID, Session Number and Seat Number on the question paper and the answer booklet. Please put all your answers on the ANSWER BOOKLET provided. No grades will be given to those answers marked on this question paper.
This is a closedbook exam. NEITHER dictionaries NOR calculators are allowed.
There are 3 parts in this exam paper and the full mark is 100, plus bonus mark 5.
All kinds of CHEATING found during the exam will result in a Grade F.
During the examination, please SWITCH OFF all your communication devices.
Good luck!
Part A True or False 20: Answer all the questions.
If the statement is true, write a T without explanation.
However, if the statement is false, indicate it with an F and you have to EXPLAIN WHY it is false. Only 1 will be given to those correct answers without explanation.

In C, a character is stored in one byte of storage space.
After you compile a source program, which is a .cpp file, you will get an executable .exe file.
C considers the variables mark and MARK to be identical.
The default case should always be added to the switch selection statement.
A variable that is known only within the function to which it is defined is called a global variable.
The arithmetic operators , , , and all have the same level of precedence.
When it is not known in advance how many times a set of statements will be repeated, no value can be used to terminate the repetition.
The word right will justify the output to the righthand side on the console.
The largest integer value that you can store in a data type short int or simply short is 32767.
From the two statements: char ch a; cout ch; you will get the output b.
Part B Multiple Choice 30: Choose the best answer for each question.
What is the major source of runtime errors?
Code incorrectly compiled.
Bad hardware.
User incorrectly specified requirements.
Assuming the program is doing what it is supposed to do.

The proper approach to debugging code involves the following EXCEPT .
using debugging tools available in your development system.
modifying the code to try and make the error vanish.
adding output statements to show which clause was executed.
adding output statements where data has been changed.

The following are all examples of what type of error?
incorrectly implemented algorithm
used a variable before assigning a value to it
swapped two parameters of the same type on a function call
forgot to designate the output parameter of a function as a reference parameter
runtime error
compile error
logical error
system error

The signature of a function consists of .
parameter list
function name
function name and parameter list
return type, function name, and parameter list

What is the output of the following code?
string sabcdefg;
cout s.substr1, 4;

A. ad
B. a
C. bcde
D. cdef

What do the following statements do?
ifstream stream;
stream.openscores.txt;
A. Open a file for input.
B. Open a file for output, the statement fails if the file already exists.
C. Open a file for output, the contents of the file is destroyed if the file already exists.
D. Open a file for input, the statement fails if the file does not exist.
Suppose x10 and y10, what is the value of x when evaluating the expression y 10 x 10?
9
10
11
True

What is the output of the following code?
bool gender true;
cout gender ? male : female endl;
true
false
female
male

What is the printout of the following switch statement in C?
char ch b;
switch ch
case a:
case A: cout ch endl; break;
case b:
case B: cout ch endl; break;
case c:
case C: cout ch endl; break;
case d:
case D: cout ch endl;

a
b
B
nothing will be printed out

Express the algebraic equation y ax3 7 in a C statement.
y a x 3 7
y a x x x 7
y a x37
y a x 3 7

What is the value for the variable sum after the following loop statement terminates?
int sum 0;
int count 0;
do
count;
sum count;
if sum 8 break;

while count 5;
5
6
7
10

Analyze the following code.
int count 0;
while count 100
Point A
cout Welcome to C! endl;
count;
Point B

Point C
count 100 is always false at Point B
count 100 is always true at Point A
count 100 is always true at Point B
count 100 is always true at Point C

If a max function is used to find the max of two integers, if you want to use the same function to find the max of two floating point number, such methodology is called:
Overwriting
Overloading
Overriding
Inline

The variables that are declared outside all functions and are accessible to all functions in its scope are called:
Static variables
Dynamic variables
Local variables
Global variables

What will be the output of the following short program
include iostream
using namespace std;
int v1 20;
int main

int v1 10;
cout Variable v1 is v1 endl;
cout Variable v1 is ::v1 endl;
return 0;

10, 20
10, 10
11, 20
20, 11

Part C Problem Solving 50: Answer all the questions.
What values are assigned to the variables in the following sequence of C statements? State the content of each variable on each line. 10
int A 8;
A 2;
int B A;
int C 3 A 3 B;
int D B ! C A B 3 C;
int E A B ? A : C;

Refer to the following C program codes, what will be the output for each case? 15
2a

void DoPrintchar x, int y
while y 0
cout x;
y;

cout endl;

int main
int i 3; cout i endl;
DoPrintA, i;
cout Finished printing i times! endl;
return 0;

2b

string s HELLO;
s1 A;
cout s endl;

2c
include iostream
using namespace std;

int main
int first 1;
int second 2;
first second;
cout The first number is first and the second number is second endl; return 0;

What isare wrong with the following C program codes? Correct them if possible. 15
3a int sum 0;
int count 0;
while count 100
sum countcount;

3b if age 18 ;
cout Age is greater than or equal to 18 endl;
else;
cout Age is less than 18 endl;

3c The following code should output the odd integers from 99 to 1:
for x99; x1; x2
cout x endl;

a What is the objective of the following program? 5

b Please show the output when the number input is 35. 5

include iostream
using namespace std;

int main

int number, i;
bool Testing true;

cout Enter an integer: ;
cin number;

for i 2; i number Testing; i

if number i 0
Testing false;

cout Counter is i endl;

if Testing
cout number is a prime number! endl;
else
cout number is not a prime number! endl;
return 0;

Part D Bonus Question 5
Write a C program to print the first 50 positive even numbers excluding zero to a text file named outfile.txt using a while loop. Print the word DONE! on the output screen of your computer when the program terminates.

Use the following names for your variables: outputfile; count; number;
The output in the text file should contain 5 integers per line.

PAGE 7 NUMPAGES 7

Student Name: Student No. : Session No.: Seat No.:

Page PAGE 1 NUMPAGES 1