| Date of Quiz: | Thu Mar-1 |
These questions are variants from the Feb 16 Programming Team Quick Questions, which were assigned as homework over the past two days.
Rules: Make one program which contains the void methods q1(), q2(),.... Use the following main():
void q1() {}
void q2() {}
void q3() {}
void q4() {}
void q5() {}
void q6() {}
void q7() {}
void main()
{
int problem;
while (true)
{
cout << "Problem
#1-7: ";
cin >> problem;
switch(problem)
{
case 1: q1();
break;
case 2: q2();
break;
case 3: q3();
break;
case 4: q4();
break;
case 5: q5();
break;
case 6: q6();
break;
case 7: q7();
break;
default: return;
}
}
}
Question 1: Read in seven integers. You are guaranteed that of the seven, you get three copies of one number and four copies of another number. Print out the number that has three copies.
Input: 6 8 6 8 8 6 8Question 2: Read in two words, output the word which contains more A's in it (count both upper and lower case A's).
Output: 6
Question 3: Read in an integer N >= 0 followed by N positive floating point numbers, and output the count of floating point numbers which are also in fact integers.
Input: 5 2.3 17.0 5.23 8 22.336Question 4: Read in three integers and output "yes" if it is possible for a triangle to have those three values for the lengths of its sides, and "no" otherwise.
Output: 2 (because 17.0 and 8 are integers)
Question 5: Read in the name of a regular polygon and a side length, and output the perimeter. The polygon will be a triangle, square, pentagon, hexagon, heptagon, or octagon.
Input: pentagon 19Question 6: Read in a positive integer N and output "yes" if the sum of the bits representing N is even and "no" otherwise.
Output: 95
Input: 38Question 7: Read in a string representing a note on a keyboard without flats (so it will be one of C, C#, D, D#, E, F, F#, G, G#, A, A#, B), followed by an integer representing the number of half-steps to transpose that note upwards, and output "yes" if the resulting note is a natural and "no" if it is a sharp.
Output: no (because 38 = 32 + 4 + 2, so the sum of bits is 3, which is odd.)
Input: C# 5
Output: no (becaue the resulting note is F#, which is not a natural)