08 Jun devry comp122 week 2 homework
Question
COMP122
Week 2 Homework
Complete the following problems.
1. Suppose you are given the following variable declarations:
int x, y;
char ch;
What values (if any) are assigned to x, y, and ch after each of these statements execute?
Assume that the input to each statement is the same: 5 28 36
a. cin >> x >> y >> ch;
b. cin >> ch >> x >> y;
c. cin >> x >> ch >> y;
d. cin >> x >> y;
cin.get(ch);
2. Suppose you are given the following variable declarations:
int x, y;
char ch;
What values (if any) are assigned to x, y, and ch after each of these statements execute?
Assume that the input to each set of statements is as follows:
13 28 D
14 E 98
A B 56
a. cin >> x >> y;
cin.ignore(50, ‘\n’);
cin >> ch;
b. cin >> x;
cin.ignore(50, ‘\n’);
cin >> y;
cin.ignore(50, ‘\n’);
cin.get(ch);
3. Suppose you are given the following variable declarations:
int x, y;
double z;
char ch;
Assume you have the following input statement:
cin >> x >> y >> ch >> z;
What values (if any) are stored in x, y, z, and ch if the input is:
a. 35 62. 78
b. 86 32A 92.6
c. 12 .45A 32
4. Write a C++ statement that uses the manipulator ‘setfill’ to output a line containing 35 asterisk characters.
5. What is the output from the following statements?
a. if ( 60 <= 12 * 5)
cout << “Hello”;
cout << ” There”;
b. if (‘a’ > ‘b’ || 66 > static_cast<int>(‘A’))
cout << “#*#” << endl;
c. if (7 <= 7)
cout << 6 – 9 * 2 / 6 << endl;
d. if (7 < 8)
{
cout << “2 4 6 8” << endl;
cout << “1 3 5 7” << endl;
}
e. if (5 < 3)
cout << “*”;
else if (7 == 8)
cout << “&”;
else
cout << “$”;
6. Suppose that you have the following variable declarations:
int x = 10;
int y = 15;
int z = 20;
Determine whether the following expressions are true or false.
a. !(x < 10)
b. x <= 5 || y > 15
c. (x != 5) && (y == z)
d. x <= z && (x + y >= z)
7. What is the output of the following code fragment?
int x = 100;
int y = 200;
if (x > 100 && y <= 200)
cout << x << ” ” << y << ” ” << x + y << endl;
else
cout << x << ” ” << y << ” ” << 2 * x – y << endl;
8. Given a char variable called gender, write C++ statements to output “Male” if gender contains upper or lower case M, “Female” if it contains upper or lower case F, or “Invalid Gender” if it contains anything else. Use if / else if statements.
9. Given a char variable called gender, write C++ statements to out “Male” if gender contains upper or lower case M, “Female” if it contains upper or lower case F, or “Invalid Gender” if it contains anything else. Use a switch statement.
10. What is the value of the beta variable after the following code executes?
int beta = 3;
switch(beta)
{
case 3:
beta += 3;
case 1:
beta++;
break;
case 5:
beta += 5;
case 4:
beta += 4;
}
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
