If there are no errors in the program, show what will be printed by each of the following programs. If there are any errors in the program explain what is wrong. 1. #include <iostream.h> 2. #include <iostream.h> void two(int&,int&,int&); void two(int&,int&,int&); int main() int main() { { int x,y,z; int a,b,c; two(x,y,z); cin >> a >> b >> c; cout << x << " "<< y two(a,b,c); << " "<< z; cout << c << " " << b } << " " << a; void two(int& a, int& z, int&b) } { void two(int& x,int& c,int& y) cin >> b >> z >> a; { a = a * b + z; int a; } cin >> a >> y; c = x + c + 20; DATA: 2 1 5 } DATA: 1 2 3 4 5 3. #include <iostream.h> 4. #include <iostream.h> void four(int&, int); void four(int&, int&); int main() int num; { int main() int a, b, c; { a = 1; int x; b = 2; int y; c = four(a, b); x = 10; cout << a << " " << b y = 20; << " " << c; num = 30; } cout << x << " " << y void four(int&a, int b); << " " << num; { four(x,y); cout << a << " " << b << endl; cout << x << " " << y } << " " << num; } void four(int& y, int& x) { int num; num = 20; y = 3; x = 6; } 5. #include <iostream.h> int main() { int i; i = 10; { int i; i = 20; cout << i << endl; { int i; i = 30; cout << i << endl; } cout << i << endl; } cout << i << endl; } 6. #include <iostream.h> void func1(); int a = 3; int main() { int b = 7, a = 8; cout << a << ' ' << b << endl; func1(); } int c = 2; void func1() { int d = 12; cout << c << ' ' << a << ' ' << b << ' ' << d; } 7. #include <iostream.h> void func1(int); void func2(); void func3(); int i = 5; int main() { int i= 6; cout << "The value of i is " << i << endl; func1(i); func2(); func3(); } void func1(int i) { cout << "The value of i in func1 is " << i << endl; } void func2() { cout << "The value of i in func2 is " << i << endl; } void func3() { int i = 8; cout << "The value of i in func3 is " << i << endl; } 8. #include <iostream.h> void func(); int main() { func(); func(); func(); } void func() { int i = 0; static int j = 0; i++; j++; cout << i << ' ' << j << endl; } 9. Write a function called maxAndMin that reads 12 numbers from the user and returns the largest and the smallest of the numbers that were entered. 10. Write a prototype for maxAndMin. 11. Write the statements to call maxAndMin and print the values that were returned. 12. Write a function called dayTypes to read in 30 temperatures from the file "temp.in". The function should count and return the number of hot days, the number of nice days, and the number of cold days. Use the following to decided whether a day is hot, cold, or nice: temperature type of day < 60 cold 60-84 nice 85 and up hot 13. Write a prototype for the function dayTypes. 14. Write the statements to call dayTypes and print the number of cold days, nice days, and hot days.
Remember to type your answers and to make two copies of each homework assignment. One copy is submitted to me and the other you keep to use in the group discussions.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2004