with complete solutions
Write the assignment statements that perform the following operations with int variable i, double
variables d1 and d2, and char variable c:
a.) Add 2 to d1 and store the result in d2. - correct answer ✔✔d2 = d1 + 2;
Write the assignment statements that perform the following operations with int variable i, double
variables d1 and d2, and char variable c:
b.) Multiply d2 times 4 and store the result in d1. - correct answer ✔✔d1 = d2 * 4;
Write the assignment statements that perform the following operations with int variable i, double
variables d1 and d2, and char variable c:
c.) Store the character 'K' in c. - correct answer ✔✔c = 'K';
Write the assignment statements that perform the following operations with int variable i, double
variables d1 and d2, and char variable c:
d.) Store the ASCII code for the character 'K' in i. - correct answer ✔✔i = 'K';
Write the assignment statements that perform the following operations with int variable i, double
variables d1 and d2, and char variable c:
e.) Subtract 1 from i and store the result back in i. - correct answer ✔✔i = i - 1;
, Write the C++ code for a program that calculates how many days are left until halloween, when given as
an input how many weeks are left until halloween. Use variable named weeks and days. - correct answer
✔✔#include<iostream>
using namespace std;
int main()
{
int weeks, days;
cout<<"Enter number of weeks: ";
cin>>weeks;
days = weeks * 7;
cout<<"Number of days is "<<days<<endl;
return 0;
}
Assume the following variables are defined:
int age;
double pay;
char section;
Write a single cin statement that will read input into each of these variables. - correct answer
✔✔cin>>age>>pay>>section;
Is the following code legal? Why or why not?
const int DAYS_IN_WEEK;