Engr 101 - Exam 1_key F12

Your program will be used in the upcoming election to

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nters an infinite loop and never finishes. • The screen output of the program using the underscore to denote any spaces (i.e. 26_12_7_). Assume that #include <iostream> and using namespace std; are included at the beginning of each program. int main() { void proc(int & x) { int x = 5, y = 10; while (x < 10) { if ((y % 2) == 0) { cout << y << " " << x << " "; } x++; y--; } return 0; cout << x; x--; return; } int main() { int y = 5; while (y >= 0) { proc(y); } return 0; } } Answer: Answer: 10_5_8_7_6_9_ 543210 int func(int x) { cout << x; x--; return x; } int main() { int y = 5; while (y >= 0) { y = func(y); } return 0; } Answer: 543210 ENGR 101: Intro to Computers & Programming - Fall 2012 Page 4 of 8 Uniqname: ____________________________ Question 3 (continued) int main() { int x = 10; while (x != 4) { if (x > 7) { cout << (x + 1) << " "; } else { cout << (x - 1) << " "; } x--; } return 0; int main() { int m = 10; while (m > 0) { cout >> (m – 10); m++; } return; { } Answer: Answer: 11_10_9_6_5_4_ Does not compile ENGR 101: Intro to Computers & Programming - Fall 2012 Page 5 of 8 Uniqname: ____________________________ Question 4 – Write some code (35 points) For this question, write code for the main() function of a program in the space provided on the next page (you have been given the scaffolding). Your program will be used in the upcoming election to summarize the outcome based on results from an unknown number of precincts. Your program will gather its input from a file called votes.txt. The data that your program calculates will be output to a file called results.txt and also to the screen. Make sure to...
View Full Document

This note was uploaded on 11/15/2013 for the course ENGR 101 taught by Professor Ringenberg during the Winter '07 term at University of Michigan.

Ask a homework question - tutors are online