Answer to Question #165890 in C++ for blessing

Question #165890

Students in Programming 1 would like to understand the concept of Ohm’s law. You are

required to write an application that will help students to calculate the voltage in an electric

circuit using the formula below.

V = IR

Where V= volatge

I = Current

R- Resistance




Current

0.62

14.89

13.21

16.55

18.62

9.47

6.58

18.32

12.15

3.98

Resistance Voltage

4.0        0

8.5        0

6.0        0

7.35       0

9.0        0

15.3       0 

3.0        0

5.4        0

2.9        0

4.8        0


Write a C++ application that will help the students to understand the concepts:

4.1 Create a C++ called Circuit and save it in a file called Circuit.cpp.

4.2 Declare all necessary variables and constants.

4.3 Declare two parallel arrays named current, resistance and initialise them using the

information given above.

4.4 Declare another parallel array called voltage populate by calling using default values.


4.5 Create a menu that will iterate until the user enters an invalid number. Create this menu

by calling the function menus. There are five possible menu selections numbered from

1 to 7, if the user enters 8 or any other number the program must terminate.


NB: Make use of the switch statement for the menu selection.

Menu

Option

Description

1 Display all

 Display all circuit details as shown in Figure 4.1.

2 Search volts: (See Figure 4.2)

 The user must be prompted to enter the volts that he or she would like to

search for.

 The volts must then be searched in the corresponding array.

o If the value is found or not an appropriate message must be

display as shown in Figure 4.2.

3 Search volts and indicate where it was found : (See Figure 4.2)

 The user must be prompted to enter the volts that he or she would like

to search for.

 The volts must then be searched in the corresponding array.

o If the value is found it must display the value, the index at which

it was found as well as the number of eminent for that particular

volatge or an appropriate message must be display as shown in

Figure 4.2.

4 Find the highest voltage (See Figure 4.3)

 Display the highest voltage.

5 Find highest volatge with corresponding details: (See Figure 4.3)

 Display the highest volts with their corresponding details

6 Display average volatge (See Figure 4.4).

 Calculate and display average voltage.

7 Display number of measurements that are above the average volatge (See

Figure 4.4).

8 or any

other key

Exit : (See Figure 4.5)


1
Expert's answer
2021-02-23T04:05:12-0500
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
    float current[10] = {0.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98};
    float resistance[10] = {4.0, 8.5, 6.0, 7.35, 9.0, 15.3, 3.0, 5.4, 2.9, 4.8};
    float voltage[10] = {0};
    
    cout << "]|  Menu  |[\n";
    cout << "1. Display all\n";
    cout << "2. Search volts\n";
    cout << "3. Search volts and indicate where it was found\n";
    cout << "4. Find the highest voltage\n";
    cout << "5. Find highest volatage with corresponding details\n";
    cout << "6. Display average volatge\n";
    cout << "7. Display number of measurements that are above the average volatge\n";
    cout << "Press 8 or other any key to exit except 1 to 7\n";
    
    int option;
    while (true) {
        cout << "\nSelection: "; cin >> option;
        switch (option) {
            case 1 : {
                cout << setw(15) << "Currents" << setw(15) << "Resistances" << setw(15) << "Voltages" << endl;
                for (int i = 0; i < 10; i++) {
                    voltage[i] = current[i] * resistance[i];
                    cout << setw(14) << current[i] << "A" << setw(14) << resistance[i] << "Ω" << setw(14) << voltage[i] << "V" << endl;
                }
                break;
            }
            case 2 : {
                float searchVoltage;
                int count = 0;
                cout << "Enter voltage: "; cin >> searchVoltage;
                for (int i = 0; i < 10; i++) {
                    if (searchVoltage == voltage[i]) {
                        cout << "Searched voltage is found.";
                    }
                    else {
                        count++;
                    }
                }
                if (count == 10) {
                    cout << "Searched voltage is not found.";
                }
                break;
            }
            case 3 : {
                float searchVoltage;
                int count = 0;
                cout << "Enter voltage: "; cin >> searchVoltage;
                for (int i = 0; i < 10; i++) {
                    if (searchVoltage == voltage[i]) {
                        cout << "Searched voltage is found at " << i + 1 << " - row";
                    }
                    else {
                        count++;
                    }
                }
                if (count == 10) {
                    cout << "Searched voltage is not found.";
                }
                break;
            }
            case 4 : {
                float maxVoltage = voltage[0];
                for (int i = 0; i < 10; i++) {
                    if (maxVoltage < voltage[i]) {
                        maxVoltage = voltage[i];
                    }
                }
                cout << "Max voltage is " << maxVoltage << endl;
                break;
            }
            case 5 : {
                float maxVoltage = voltage[0];
                cout << setw(15) << "Currents" << setw(15) << "Resistances" << setw(15) << "Voltages" << endl;
                for (int i = 0; i < 10; i++) {
                    if (maxVoltage < voltage[i]) {
                        maxVoltage = voltage[i];
                    }
                }
                for (int i = 0; i < 10; i++) {
                    if (maxVoltage == voltage[i]) {
                        cout << setw(14) << current[i] << "A" << setw(14) << resistance[i] << "Ω" << setw(14) << voltage[i] << "V" << endl;
                    }
                }
                cout << "Max voltage is " << maxVoltage << endl;
                break;
            }
            case 6 : {
                float avarageaVolatage = 0;
                for (int i = 0; i < 10; i++) {
                    avarageaVolatage += voltage[i];
                }
                cout << "Avarage Voltage is " << avarageaVolatage / 10 << endl;
            }
            default : break;
        }
    }
} 

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