Sei sulla pagina 1di 8

P a g e | 1

Test 1 COSC1436.002
February 13, 2014 Name_________________________

Score_________________________


Part I: Matching (10 points)

A. machine F. initialization
B. assignment G. char
C. output H. byte
D. bit I. comparison
E. input J. test


1. A(n) _________ is the amount of memory required to store a single character.

2. A(n) _________ is the amount of memory required to store a single binary digit.

3. The first parameter in a for statements parameters is the _____________.

4. The parameter in the while statement is called the _____________ condition.

5. The compiler translates your program into __________ language.

6. Data that is taken from the keyboard during program execution is called _________ data.

7. A single equal sign is called the ___________ operator

8. The___________ data type can hold a single letter or digit as defined in the ASCII table.

9. A payroll report is an example of program ___________.

10. A double equal sign is used for ____________.

P a g e | 2

Part II: Conversion (10 points)

Convert the following decimal numbers into binary and hexadecimal:

Binary Hexadecimal

1. 127

2. 83

3. 238

4. 193

5. 169


P a g e | 3



Part III: Programming (10 points)

Fill in the missing keywords, etc to make the output as shown below:

OUTPUT:

Please enter radius of circle> 5
The circumference is 31.41.





#__________ <stdio.h>
#__________ PI 3.14159

int
__________(void)
{
________ radius;
________ circum;

printf("Please enter radius of circle> ");
scanf("%f", _________);
circum = _______________;
printf("The circumference is __________.\n", ___________);

___________ (0);
}


P a g e | 4

Part IV: Pseudocode (10 points)

Break down the following problem using top-down design and show your pseudocode:

Calculate the area of a triangle using the formula area = base * height, outputting the result
to a file.

















Part V: Coding (10 points)

Write the C code for the above problem. The output file (triangle.txt) should include three
columns:
Base Height Area

Ex:
10 5 25






P a g e | 5

Part VI: Coding (10 points)

Complete the program below so that it displays the value of n and the message " is positive." if n is
positive. If n is negative, the program should display the value of n and the message " is negative."
If n is zero, the program should produce no output at all.

#include <stdio.h>

int
main(void)
{
double n;

printf("Enter a number> ");
scanf("%lf", &n);











return (0);
}



P a g e | 6

Part VII: Logic (5 points)

Assuming the following declaration, fill the missing entries in the table with 1 (true) or 0 (false).

int x = 11;
int y = 6;
int z = 1;
char c = k;
char d = y;

Expression value
x > 9 && y !=3 1
x ==5 || y != 3
!(x > 14)
5 && y != 8 || 0
c >= A || c <= z
C = a && c <= z



Part VIII: Finding Errors (5 points)

Circle the errors in the code below and give the corrections above to error:

#include <stdio.h>

int getArea(int,int);

int main()
{

float base = 10.0

float area = 20.0;

getArea(base,height);

printf(A rectangle with base %d and height %d has area
%d.,base,height,area);

return (0);

}

float getArea(float base,float height)
{
float area;

area == base * height;

return (area);
}

P a g e | 7

Part IX: Desk Checking (20 points)

A. Determine the output of the given program:


#include <stdio.h>

void main (void)
{
int total=0;
int i;
int j;


for(i=1; i<=7; i=i+3)
{
for(j=10; j<=30; j=j+10)
{
if (j % i == 0)
{
total *= 2;
}
else
{
total += (i + j);
}

printf("%d %d - %d\n", i,j,total);

}
}

}

P a g e | 8

B. Determine the output of the given program:

#include <stdio.h>

void main (void)
{
int i = 0;
int j = 0;
float product;

while (i < 10 )
{
j = i++;
switch (j)
{
case 1:
case 2:
case 3:
printf("Low \n");
break;
case 4:
case 5:
case 6:
printf("Medium \n");
break;
case 7:
case 8:
printf("Medium ");
case 9:
case 10:
printf("High \n");
break;
default:
printf("Unknown \n");
break;
}
}
product = (float)(i * j);
printf("i * j = %1.2f\n",product);
}

Potrebbero piacerti anche