Answer to Question #325664 in C++ for Raphael Caamano

Question #325664

1. Write a complete C++ application to prompt the user for the double voltage and resistance of a circuit, and call function calcurrent to calculate and display the current of the circuit.

Use the following statement to calculate the current:

 

double current = voltage / resistance

 

 

2. Write a C++ program to calculate the product of all even numbers from 1 to 13 using a for loop.

 

 

 

 

3. Write a C++ Program to generate a random from the following list of numbers

 


  1. 1 to 535 (one from the list)
  2. -14 to 190 (one from the list)
  3. 12, 24, 36, 48, 60 (one from the list)
  4. 0 to 241 (one from the list)
  5. 42 to 90 (one from the list)


Put the above statements in a C++ program and run the program and print the generated numbers


1
Expert's answer
2022-04-08T01:50:17-0400

1

#include <iostream>
using namespace std;


int main() {
    double voltage, resistance;
    cout << "Enter a voltage (V): ";
    cin >> voltage;
    cout << "Enter a resistance (Ohm): ";
    cin >> resistance;


    double current = voltage / resistance;
    cout << "Current is " << current << " A";


    return 0;
}


2

#include <iostream>
using namespace std;


int main() {
    int prod = 1;


    for (int i=1; i<=13; i++) {
        if (i % 2 == 0) {
            prod *= i;
        }
    }
    cout << "The product of all even numbers from 1 to 13 is " << prod << endl;
    return 0;
}


3

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;


int random(int low, int hi) {
    return rand() % (hi - low + 1) + low;
}



int main() {
    srand(time(nullptr));


    int i1 = random(1, 535);
    cout << "1: " << i1 << endl;


    int i2 = random(-14, 190);
    cout << "2: " << i2 << endl;


    int i3 = 12 * random(1, 5);
    cout << "3: " << i3 << endl;


    int i4 = random(0, 241);
    cout << "4: " << i4 << endl;


    int i5 = random(42, 90);
    cout << "5: " << i5 << endl;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS