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
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
#include<iostream>
using namespace std;
int main(){
int V,I,R;
V = I*R;
cout<<"Enter current"<<endl;
cin>>I;
cout<<"Enter resistance in ohms"<<endl;
cin>>R;
cout<<"voltage="<<I*R<<endl;
return 0;}
Comments
Leave a comment