I apologize for not posting this over the weekend. Because I ended up not making this available, we will do this as the in class activity for today. You don't need to turn it in. I will provide the answers on Thursday and we will spend some time on any questions you might have then.
The questions on this test are meant to be representative of the type and structure of the questions that you will be asked on the midterm and the range of difficulty - not the content of the questions themselves. The content could be the same as what is covered here but it can also include anything listed in any the objectives up to and including class 12. The midterm will consist of about half as many questions as this practice test. The practice test is harder than the midterm.
It is possible that you will see one or more of these questions, nearly verbatim on the midterm.
On the day of the midterm you will be provided a printed copy of the exam.
Define computer program.
What is one advantage of a high level computer programming language over a low level computer programming language.
What is the difference between program syntax and program semantics.
In your home directory on the UMBC Linux server, you have a a directory called cmsc104
. In the cmsc104
directory are two directories called class1
and class2
.
You have just used the terminal (or PuTTY) to log into the UMBC Linux server. What command would you type
to get to the class2
directory?
Define variable
Which of the follow are valid variables names in C?
32items
radius
hello;world
printf
return
theNumber32
Given the following:
#include <stdio.h> // A refers to this line
int main()
{
// B refers to this line
printf("Hello, world!\n"); // C refers to this line
return 0; // D refers to this line
}
For each of items below, which line from the code above best fits the description
The start of the execution of the program
Exits the program
A function call
Preprocessor directive
Given the following program:
#include <studio.h>
int main()
{
printf('Hello, world!\n")
return 0;
}
Identify 3 errors and their corrective action
Any program we've written in this class.
Given the following program:
#include <stdio.h>
double area(radius)
{
return radius * radius * 3.14;
}
int main()
{
double radius1 = 5.0
double area = area(double radius1);
printf("The area of the circle with radius %lf, is %lf", radius1, area);
return 0;
}
Identify 3 errors and their corrective action
The in class assignments for classes 7 and 8
Given the following program:
#include <stdio.h>
int main()
{
int theNumber10 = 10;
int theNumber20 = 20;
int theNumber30 = 30;
printf("the first number is %d\n", theNumber20);
printf("the second number is %d\n", theNumber10);
printf("the third number is %d\n", theNumber30);
return 0;
}
Write the output below:
Given the following program:
#include <stdio.h>
int main()
{
int theNumber10 = 10;
int theNumber20 = 20;
int theNumber30 = 30;
theNumber10 = 35;
printf("the first number is %d\n", theNumber20);
printf("the second number is %d\n", theNumber10);
printf("the third number is %d\n", theNumber30);
theNumber30 = 55;
return 0;
}
Write the output below:
Given the following program:
#include <stdio.h>
int main()
{
int theNumber10 = 10;
int theNumber20 = 20;
int theNumber30 = 30;
{
int theNumber20 = 100;
printf("the first number is %d\n", theNumber20);
}
{
int theNumber10 = 0;
}
printf("the second number is %d\n", theNumber10);
{
theNumber30 = 5;
}
printf("the third number is %d\n", theNumber30);
printf("the fourth number is %d\n", theNumber20);
return 0;
}
Write the output below:
Choose the best answer from the four options.
The three categories of basic data types in C are:
1) double, float, int
2) integers, decimal numbers, characters
3) functions, statements, expressions
4) high level, low level, compiled
Define variable initialization
Write a variable declaration that you would use to store the result of calculating
the area of triangle where the base is 4.2
(you just need to declare a variable
with a valid name of the correct type).
Write a variable declaration that you would use to store the result of calculating
the area of triangle where the base is 4.2
(you just need to declare a variable
with a valid name of the correct type).
What mathematical operator would you use to divide 4.2
by 5.3
in C (the operator
as you would type it in your source code - i.e. the character)?
What mathematical operator would you use to calculate the remainder of dividing 7
by 4
in
C (the operator as you would type it in your source code - i.e. the character)?
Define function arguments
Given the following function definition
A B C
⬇ ⬇ ⬇
double power(double base, double power)
{
// D is this section betwen `{` and `}`
}
For each of items below, which item from the code above best fits the description
A function argument
The function body
The function return type
The function name
defining a function from class 7 notes
the sample program from class 7
If I told you that the function from #19 returns the calculation of the first argument (base
)
raised to the power of the second argument (power
), write the code to declare an appropriate
variable and store the result of 3
raised to the power of 4
(don't write the whole program, just
the part that declares the variable, calls the function and assigns the result).
using a function from class 7 notes
the sample program from class 7
What is a benefit of using a function over repetitive logic in your code
Given the following four lines of code:
double theNumber;
printf("Enter a number: ");
printf("1.0 plus %lf is %lf", theNumber, 1.0 + theNumber);
scanf("%d", theNumber);
Identify 3 errors and their corrective actions
Given the following line of code:
printf("The number is: %lf", 24.65);
Modify it so that it prints 24.65
to three decimal places in a field that is 6 characters wide
Given the following program:
#include <stdio.h>
int main()
{
printf("Hello\n");
if (10 < 12)
{
printf("Hello\n");
}
else
{
printf("Goodbye\n");
}
}
What is the output?
Given the following program:
#include <stdio.h>
int main()
{
printf("Hello\n");
if (13 < 12)
{
printf("Hello\n");
}
else if(10 == 11)
{
printf("Goodbye\n");
}
}
What is the output?
Given the following program:
#include <stdio.h>
int main()
{
printf("Hello\n");
if (13 < 12)
{
printf("Hello\n");
}
else if (10 == 10)
{
printf("Goodbye\n");
}
if (11 < 12)
{
printf("Goodbye\n");
}
}
What is the output?
Given the following program:
#include <stdio.h>
int main()
{
int number1 = 10;
int number2 = 15;
int number3 = 0;
if (number1 > number2)
{
number3 = number2 - number1;
number1 = number2;
}
else
{
number3 = number1 * number2;
number2 = number1 + number2;
}
if (number1 == number2)
{
number3 = number3 / 2;
}
else if (number1 < number2)
{
number3 = number3 - 5;
}
else
{
number3 = number3 + number1;
}
printf("Number 3 is %d\n", number3);
return 0;
}
What is the output of the program?