Alright guys I have my programs first bit done. Here is the files code that it is reading from:
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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream outputFile;
outputFile.open ("information.txt");
string line1;
string line2;
string line3;
string line4;
string line5;
string line6;
string line7;
string line8;
string line9;
string line10;
string line11;
line1 = "Height\t\tRadius\t\tCalculation\tType\n";
line2 = "1.0\t\t1.0\t\tC\n";
line3 = "1.0 1.0 V\n";
line4 = "1.0 1.0 S\n";
line5 = "1.0 1.0 D\n";
line6 = "1010.0 250.0 C\n";
line7 = "12.3 3.25 V\n";
line8 = "123.0 43.0 S\n";
line9 = "12.3 3.25 K\n";
line10 = "1.12 2.13 C\n";
line11 = "-999";
outputFile << line1;
outputFile << line2;
outputFile << line3;
outputFile << line4;
outputFile << line5;
outputFile << line6;
outputFile << line7;
outputFile << line8;
outputFile << line9;
outputFile << line10;
outputFile << line11;
outputFile.close();
cout << "The data has been entered" << endl;
return 0;
}
|
I realize there may be some extra coding in there but I'm not sure yet. I'm doing this homework one step at a time. I am going to now post the assignment instructions and then my program so far.
Instructions:
EGR 126
Program 4 – Modification and enhancement of an existing program
The objective of this Program is to revisit a previous program for modification and enhancement, specifically the addition of looping, input validation, and the use of a file for multiple inputs. Please review the description for Program 2, which calculated volume, circumference and surface area values for a right circular cylinder of specified size.
The assignment for this program is to modify the code from Program 2 so that the information and specifications for several different cylinders can be processed in one run using a while or do-while loop. Additionally, for each set of cylinder data, only one of the three values is to be printed out: volume, circumference OR surface area, not all three.
In order to specify only one type of calculation, not all three, an input parameter will be used to indicate which type of calculation to perform.
The option for determining the radius of a cylinder with the same height but a volume 50% greater is eliminated.
Design your program to read all the input values from a file. Set up your input file to contain the height, radius, and calculation type for each cylinder listed in sequential order. The first line of the file is a phrase that describes how the file is set up. Read this phrase and print it. The last entry in the file is a sentinel to indicate the end of data (something like -999). Do not use the sentinel as a value in your calculation.
Set up your data file to contain the following values to test your program. The first number in each line is the height, the second number is the radius, and the last number is the calculation type, where C is for Circumference, V is for
Volume, S is for Surface Area.
1.0 1.0 C
1.0 1.0 V
1.0 1.0 S
1.0 1.0 D
1010.0 250.0 C
12.3 3.25 V
123.0 43.0 S
12.3 3.25 K
1.12 2.13 C
To determine the type of calculation to perform, the code should include a switch statement. You will switch on “character” based on the calculation type requested. Note that calculation type K and D are invalid types, so for those cases (or for any invalid type) print the input values, and an informative and appropriate message, and continue processing.
Keep count of the number of data sets successfully processed. (those with valid calculation types) You should include comments in your code.
You may choose to print to the screen or to an output file. Be sure to print the height, radius and requested calculation values, all appropriately labeled. Also print the number of data sets successfully processed. Follow our standard labeling requirements for name, program, date and purpose.
Use 2 decimal places of precision.
Be sure to turn in prints of the source code, the input file and the output.
Because we are testing the program with a fixed number of data sets, a for loop would probably be a better choice, but please use a while or do-while in this program.
Updated 8/20/2016
Here is my programs code:
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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inputFile;
string word1;
string word2;
string word3;
string word4;
cout << "\t" << endl;
cout << "\t" << endl;
inputFile.open("information.txt");
cout << "Reading File information. \n";
cout << "\t" << endl;
cout << "\t" << endl;
inputFile >> word1;
inputFile >> word2;
inputFile >> word3;
inputFile >> word4;
cout << word1 << " " << word2 << " " << word3 << " " << word4 << endl;
cout << "\t" << endl;
cout << "\t" << endl;
inputFile.close();
return 0;
}
|