Answered You can hire a professional tutor to get the answer.

QUESTION

This C++ program is a menu driven program that asks whether the user would like to use the Ohm's Law Calculator or the Electrical Material and Labor

This C++ program is a menu driven program that asks whether the user would like to use the 

Ohm's Law Calculator or the Electrical Material and Labor Calculator for up to 100 employees

My assignment is:

Add the ability to save data to disk in one or more files. 

The menu(s) should give the user the option to save or retrieve data.

I would like to ask the user at the main menu if they would like to save their data to a file

and also if the user would like to retrieve the data from the file. A .txt file would work fine.

The user should be prompted for a file name. I would like the output of either program selected

in the main menu, Ohm's Law Calculator or Electrical Calculator, to be written to the file to 

be later retrieved. Each time the program is used the new data overwrites the previous data.The

data that I would like to be saved is the OUTPUT OF THE CODE when the user is finished.

The following is my current code:

#include<iostream>

#include<iomanip>

#include<string>

using namespace std;

void calcVoltage() {

float i, v, r;

cout << "Enter Current in amps";

cin >> i;

cout << "Enter Resistance in ohms";

cin >> r;

v = i * r;

cout << "Voltage Required is=" << fixed << setprecision(2) << v << "volts" <<endl;

cout << endl;

}

void calcCurrent() {

float i, v, r;

cout << "Enter Voltage in volts";

cin >> v;

cout << "Enter Resistance in ohms";

cin >> r;

i = v / r;

cout << "Current Required is=" << fixed << setprecision(2) << i << "amps";

}

void calcResistance() {

float i, v, r;

cout << "Enter Current in amps";

cin >> i;

cout << "Enter Voltage in volts";

cin >> v;

r = v / i;

cout << "Resistance Required is=" << fixed << setprecision(2) << r << "ohms";

}

void getMaterialInfo(string& materialType, int& wireGuage, double& costFoot, double& lengthWire) {

cout << "Enter Material Type (AL or CU)" << endl;

cin >> materialType;

cout << "Enter Wire Guage" << endl;

cin >> wireGuage;

cout << "Enter Cost per Foot" << endl;

cin >> costFoot;

cout << "Enter Length of Wire" << endl;

cin >> lengthWire;

}

void getEmployeeInfo(int &numEmployees, int hoursWorked[100], double hourlyPay[100]) {

cout << "Enter Number of Employees up to 100" << endl;

cin >> numEmployees;

for (int count = 0; count < numEmployees; count++) {

cout << "Employee: " << count + 1 << endl;

cout << "Enter Number of Hours Worked" << endl;

cin >> hoursWorked[count];

cout << "Enter Hourly Pay" << endl;

cin >> hourlyPay[count];

}

}

int main()

{

int choice;

cout << "Ohm's Law Calculator and Electrical Material and Labor Calculator" << endl;

cout << "What can I help you with?" << endl;

cout << "1. for Ohm's Law Calculator 2. for Electrical Material and Labor Calculator";

cin >> choice;

switch (choice)

{

case 1:

int choose;

cout << "Ohm's Law Calculator" << endl;

cout << "What can I help you find?" << endl;

cout << "1. for Voltage 2. for Current 3. for Resistance";

cin >> choose;

switch (choose)

{

case 1:

calcVoltage();

break;

case 2:

calcCurrent();

break;

case 3:

calcResistance();

break;

return 0;

}

break;

case 2:

string materialType;

int wireGuage, numEmployees;

double costFoot, lengthWire, materialCost, laborCost, totalCost;

getMaterialInfo(materialType, wireGuage, costFoot, lengthWire);

cout << "Material Type: " << materialType << endl;

cout << "Wire Guage: " << wireGuage << endl;

cout << "Cost per Foot: " << costFoot << endl;

cout << "Length of Wire: " << lengthWire << endl;

int hoursWorked[100];

double hourlyPay[100];

getEmployeeInfo(numEmployees, hoursWorked, hourlyPay);

cout << "Number of Employees: " << numEmployees << endl;

for (int count = 0; count < numEmployees; count++)

{

cout << "Number of Hours Worked: " << hoursWorked[count] << endl;

cout << "Hourly Pay: " << hourlyPay[count] << endl;

}

materialCost = costFoot * lengthWire;

laborCost = 0;

for (int count = 0; count < numEmployees; count++) {

laborCost += hoursWorked[count] * hourlyPay[count];

}

totalCost = materialCost + laborCost;

cout << "Material Cost is $" << fixed << setprecision(2) << materialCost << endl;

cout << "Labor Cost is $" << fixed << setprecision(2) << laborCost << endl;

cout << "Total Cost is $" << fixed << setprecision(2) << totalCost << endl;

}

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question