Hi Everyone,
I am new to C++ and am trying to complete a program that will read integers from a .txt document, convert them in the program, and then write them in a separate .txt document. i am encountering some issues that i cannot find answers for in the forum and i am hoping someone here can point me in the right direction. My first issue is that i have no idea how to take several integers from a .txt file, run those through a formula, and then have the conversions (myc2f,myf2c) outputted to a separate, but predetermined .txt file. the second issue i am having with this assignment is that i cannot figure out how to remove an option from the menu once it has been selected. i will copy the whole assignment below so that there is at least a perspective. thank you in advance for your time.
p.s. i hope this isn't coming off as me wanting someone to do my work for me, i just need a bit of direction.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
int option, x;
int line = x;
double Farenheit, Celsius;
int myc2f, myf2c;
ifstream infile;
ofstream outfile;
cout << "=========================================================" << endl
<< " Thomas Hardy" << endl
<< " Solution for Assignment #6" << endl
<< "=========================================================\n\n";
do
{
cout<< " 1) Convert Celsius to Fahrenheit" << endl
<< " 2) Convert Farenheit to Celsius" << endl
<< " 3) Exit" << endl;
cin >> option;
if (option == 1)
{
infile.open("data_Celsius.txt");
myc2f = x*1.8 + 32;
outfile.open("Hardy_Fahrenheit_Output.txt");
cout << "Celsius to Fahrenheit process is initiated" << endl
<< "Celsius to Fahrenheit process is complete\n\n" << endl
<< string(50, '\n'); //clear screen 50 lines
}
else if (option == 2)
{
infile.open("data_Fahrenheit.txt");
myf2c = (x - 32)*(5 / 9);
outfile.open("Hardy_Celsius_Output.txt");
cout << "Fahrenheit to Celsius process is initiated" << endl
<< "Fahrenheit to Celsius process is complete\n\n" << endl;
}
else if (option != 3)
{
cout << "Invalid entry" << endl;
}
else
{
cout << "------------------------------------" << endl;
cout << "End of Assignment # 6" << endl;
cout << "------------------------------------" << endl;
system("pause");
return 0;
}
} while (option != 3);
system("pause");
return 0;
|
-Build a command-line C++ application that allows user to convert pre-recorded temperature values from Fahrenheit to Celsius or from Celsius to Fahrenheit. Related data is provided along with this assignment.
Once completed, user will be prompted by three options;
• Option 1 Convert Celsius to Fahrenheit
• Option 2 Convert Fahrenheit to Celsius
• Option 3 Exit
Any other entry must lead to warning message ( i.e “ Invalid Entry”). And then, user will be asked
choose one of the listed options again. Program will not stop unless “Option 3“ is selected.
IF OPTION 1 SELECTED:
1. User will be prompted by “Celsius to Fahrenheit Process is initiated “
2. Then program reads temperatures in degrees Celsius from the given input file
(data_Celsius.txt), calls the function (myc2f) to convert the temperature to degrees
Fahrenheit, and write the converted temperatures into an output file named as
(LastName_Fahrenheit_Output.txt).
3. Then, program will produce a confirmation message on the screen “Celsius to
Fahrenheit Process is completed “
4. Then ask user to choose from remaining options (i.e. Option 2, Option 3). Get the user’s
entry, and then clear the screen.
IF OPTION 2 SELECTED:
1. User will be prompted by “Fahrenheit to Celsius Process is initiated “
2. Then program reads temperatures in degrees Fahrenheit from an input file
(data_Fahrenheit.txt), calls the function ( myf2c) to convert the temperature to degrees Celsius, and write the converted temperature into an output file named as
(LastName_Celsius_Output.txt).
3. Program will produce a confirmation message on the screen “Fahrenheit to Celsius
Process is Completed “
4. Then ask user to choose from remaining options (i.e. Option 1, Option 3). Get the user’s
entry, and then clear the screen.
IF OPTION 3 SELECTED:.
1. User will Prompted by “Exit from the Program “
2. Then, Exit from the Program.
Program will not stop unless “Option 3“ is selected.
EXPECTATIONS
You will be submitting one c++ source code document which will generate two output data files based on user’s input. You do NOT need to submit the input data files.
Minimum 3 functions must be designed.
3 functions.
1. A void function for the “MAIN MENU”.
2. myc2f (). to Convert Celsius to Fahrenheit
3. myf2c () to Convert Fahrenheit to Celsius
INPUT DATA FILES:
You will be developing code to read the input data numbers from given data files.
• Pre-recorded Celsius Data points (data_Celsius.txt)
• Pre-recorded Fahrenheit Data points (data_Fahrenheit.txt)
OUTPUT DATA FILES: Your code must produce output data files based on user preference.
IF OPTION 1 SELECTED then the output data file LastName_Fahrenheit_Output.txt
IF OPTION 2 SELECTED then the output data file LastName_Celcius_Output.txt
Do NOT submit any data file.
WARNING MESSAGE
WARNING MESSAGE 1 : There must be a warning message of “ Invalid Entry !” : if the
user enters a choice (option) which is NOT given in the menu items ( i.e. 5), user will be
prompted by “ Invalid Entry !” and the menu items must be shown again to give the user an
opportunity to make correct selection.