Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

int value = 1; int input; do { cin >> input; value = value * input; } while (inp

ID: 3553374 • Letter: I

Question

int value = 1;
int input;
do
{
cin >> input;
value = value * input;
} while (input != -1);
cout << value * -1 << endl;

Question 2. A program has a char variable response that has been assigned a value. Write a switch statement that outputs "Yes" if the variable contains lower or upper case 'y', "No" if it contains lower or upper case 'n', or "Invalid Input" for any other value.

Question 3. Write a short program that gets three integer values from the user and outputs the largest number. Make sure you include everything you need, and declare all the variables you need.
    

Question 4. Write a complete C++ console mode program (#includes, etc., but no prologue) that solves a simple DC circuit problem. Given a DC voltage source of some magnitude, find the voltage drops across the 2 resistors. The user will provide the values for the voltage source and the 2 resistor values. The formula that you will need is:

VRx = Vsupply * Rx / (Rx + Ry)                           // Voltage Divider rule

Question 1. What is the output from the following loop if the input is 5 10 2 3 -1 ?

int value = 1;
int input;
do
{
cin >> input;
value = value * input;
} while (input != -1);
cout << value * -1 << endl;

Explanation / Answer

1. 500


2.

switch(response){

case 'y':

case 'Y':

cout << "Yes";

break;

case 'n':

case 'N':

cout << "No";

break;

default:

cout << "Invalid Input";

}

3.

#include<iostream>

using namespace std;


int main(){

int a, b, c;

cin >> a >> b >> c;

if(a > b && a > c) cout << a;

else if(b > a && b > c) cout << b;

else cout << c;

return 0;

}



4.

#include<iostream>

#include<iomanip>

using namespace std;


int main(){

float V, Rx, Ry, Vx, Vy;

cout << "Voltage? ";

cin >> V;

cout << "Value of Ra and Rb: ";

cin >> Rx >> Ry;

if(V <=0 || Rx <= 0 || Ry <= 0){

cout << "Invalid input!! Values should be greater than 0 ";

}

else{

Vx = V * Rx / (Rx + Ry);

Vy = V * Ry / (Rx + Ry);

cout << fixed << setprecision(3) << "Va = " << Vx << " Vb = " << Vy << " ";

}

return 0;

}



5.

#include<iostream>

using namespace std;


int main(){

int x = 75;

do{

cout << x << " " << x + 5 << " ";

x += 10;

}while(x <= 190);

return 0;

}



6.

#include<iostream>

#include<iomanip>

using namespace std;


int main(){

float deposit, rate, interest;

char more;

while(true){

cout << "Enter the initial deposit and the rate: ";

cin >> deposit >> rate;

if(deposit <= 0 || rate <= 0) cout << "The input values must be positive numbers.";

else{

interest = deposit * rate;

cout << fixed << setprecision(2) << "Interest = " << interest << " ";

}

cout << "Want to enter more data? Enter y for yes, any other character for no: ";

cin >> more;

if(more == 'y') continue;

else break;

}

return 0;

}