This exam is a total of 6 pages, including this one. It is open book, open notes, and closed neighbor!
You have 50 minutes to complete the exam. We will pick up all midterms and leave the room at 55 minutes after the hour.
There are 4 problems worth a total of 100 points. The problems are
almost equally weighted. Be careful not to spend too much time on
any particular problem. If you get stuck, go on to the next
problem. You can always come back to the one that is giving you
problems. As a guideline, allow about 12 minutes per problem,
which leaves you a couple of minutes at the end to check your work.
To ensure you have read these instructions, you get two bonus
points simply for writing your initials at the bottom of this page.
main()
{
int c, s = 0;
for (c = 1; s < 6; c++)
s += c;
printf("c=%i, s=%i\n", c, s);
return 0;
}
main()
{
int i;
for (i = 0; i < 5; i++)
switch(i)
{
case 1: printf("*\n"); break;
case 2: printf("**\n"); break;
case 3: printf("***\n"); break;
default: printf("?\n"); break;
}
return 0;
}
main()
{
int x = 10, y = 20;
double d = x/y;
printf("%.2f\n", d);
d = 7.5; y = 2; x = d / y;
printf("%i\n", x);
return 0;
}
main()
{
void tweak(double s[], int t);
int s = 4;
double t[4] = {17, 17, 17, 17};
tweak(t, s);
printf("%i\n", s);
printf("%i %i %i %I\n", t[0], t[1], t[2], t[3]);
return 0;
}
void tweak(double s[], int t)
{
s[1] = 9; s[2] = 13; t = 10;
}
/*
* Set all 10 elements of table to 100.
*/
main()
{
int table[10];
x = 10;
setTable();
}
void setTable(int v)
{
for (i = 0; i < x; i++)
table[i] = v;
}
/*
* Set all "n" elements in "t" that match "value" to "newvalue"
*/
int remove(int t[], int n, int value, int newvalue)
{
int i;
for (i = 1; i < n; i++)
if (t[i] = value)
i = newvalue;
}
/* * Read one line of input and return a count of all the commas or periods * that appear on the line. */ #includevoid countPunct() { int count = 0; while (c=getchar() != EOF) if (c == ',' && c == '.') count++; return count; }
Assume you have a function, writeN, that has already been written for you. writeN takes two arguments, a character, and a number, and writes that character that number of times. For example, writeN('x', 5) writes xxxxx. Using this function, write a new function, displayTable, where the call
produces this output:tab[0] = 3; tab[1] = -5; tab[2] = 4; tab[3] = 0; tab[4] = -6; displayTable(tab, 5, 10, '+', '-');
..........!+++....... .....-----!.......... ..........!++++...... ..........!.......... ....------!..........
A sketch of the function and its expected parameters is shown at the top of the next page. Your job is to fill in its body.
/*
Display table's parameters:
a - A table of integers. Each array element states how many
"pos" or "neg" characters to write. If the value is
positive, write that number of "pos" characters to the
right of the !, if it's negative, write that number of
"neg" characters to the left of the !
n - The number of entries in the table
dots - The maximum number of dots to produce before and after the !.
pos - The character to write for a positive array element
neg - The character to write for a negative array element
*/
displayTable(int a[], int n, int dots, char pos, char neg)
{
}
Write a program that prints only those input characters that appear between double quotes. That is, if the input is:
the output should be:Some common greetings are "Hi", "Hello", and "Howzit".
Hi Hello Howzit
[EE150 Home Page | EE150 Exam Information Page | Top Of Page]