CIS 122: Assignment #1
Due at the start of class,
Thursday, July 21 2005
Problem:
1.(20 points) What output will the following code fragments produce? Provide the answers exactly as the output.
(a)
num = 10;
x = 5;
cout << num << " ";
cout << x << " ";
cout << endl;
cout << num << endl;
(b)
x = 4;
y = 14;
y = y + x;
x = x + 1;
cout << "x = " << x << '\n';
cout << "y = " << y << '\n';
2.(40 points) The c++ program provided below contains several errors, find them out. Provide the c++ program after correction. Only change the parts with errors.
/************************
* first.cpp
* My First C++ file
* July 18, 2005
*************************/
main()
{
int num1;
int 2ndNum = 3;
cout >> 'Can I make it all right? \n'
num1 = 11;
num_3 = 2ndNum;
cout >> num1 >> " " >> 2ndNum >> " " >> num3 >> "\n";
}
3. (40 points)Do the "Critical Thinking" part of Page 45 in your text book. For extra credits (10 points), do
- Add a statement that declares 3 float type variables E, F, and G in a single statment, and initialize them to be 3.32, 4.45, and 6.61.
- Add a statement to declare an integer named age as an unsigned short. Initialize it to be any number you like, but within the range of unsigned short.
- Print E, F, and G to the screen such that the output is one line as "E = 3.32, F = 4.45, G = 6.61".
- Print age to the screen such that the output has the format like "My cat Kitty is 3 years old", if the variable age has a value 3.
Compile and run your program, Correct any errors you have made.
Submit the final program fulfilling all the requirements, and also the output.
Turn in:
Either
- A printout of your answers and/or source code file and/or the output, turn it in on class
Or,
- Submit your answer and source code file as a plain text email attachment, sent to me
at rao@cs.uoregon.edu before class.
Dan Rao
Last modified: Sat Jul 17 15:15:03 PDT 2005