Type in Word. Work with a partner and submit ONE COPY per pair. Include the following at the top of your submission:
Partner 1: Name
______________________________________________
role (driver or navigator) _____________________________
Partner 2: Name
______________________________________________
role (driver or navigator)______________________________
Please note if one
partner did not work on all problems:
---------------------------------------------------------------------------------------------------
I AM LOOKING FOR GOOD,
THOUGHTFUL ANSWERS.
#include <iostream>
using namespace
std;
int main()
{
char ans;
int num;
cout
<< endl << "Do you want to square a number?(y/n)"
<< endl; //1- START
cin
>> ans;//1 - START
while ((ans == 'y')||(ans == 'Y')) //2 - TEST
{
cout
<< "Enter number to be squared: "<< endl; //3 - ACTION
cin
>> num; //3 - ACTION
cout
<< "The square of " << num << " is "
<< num*num << endl; //3 - ACTION
cout
<< endl << "Do you want to do another square?(y/n)"
<< endl;//4 - RESTART
cin
>> ans;//4 - RESTART
}
return 0;
}
1. Type in the above program as
square.cpp. Add a comment to include your names and date. Compile and run with
different values.
2. Include a line that prints
“Good Bye” before the program exits. This should only print once.
3. What symbol does || stand for in C++?
4. What happens if you answer ‘z ‘
when asked if you want to square a number? Why? Summarize how the above
loop works, for example
_____ and _____ cause the
loop to continue, __________ causes the loop to end..
5. Modify the program to change
the || to &&. What is the
result? Why? Change it back when you have answered the question.
6. Comment out (put // at the
front of each line) any lines that are labeled 1 or START. What happens (is there an error?)? Why? Restore the lines, or
un-comment, by removing the // after you have answered the question.
7. Comment out the lines that
are labeled 4 or RESTART. What
happens, why? Un-comment the lines after you have answered the question.
#include <iostream>
using namespace
std;
int main()
{
int num;
cout
<< endl << "Enter numbers, 999 to quit" << endl;
//1 - START
cin
>> num; //1 - START
while (num != 999)
//2 - TEST
{
cout << "Number entered is: " << num << endl; //3 - ACTION
cout << "Enter numbers, 999 to quit" << endl; //4 -
RESTART
cin >> num; //4 - RESTART
}
return 0;
}