Hello,
I was given this question, in all honesty I didn't understand the question completely, but below is the code that I tried
Part 1: Create a text file by entering user input from the keyboard. the data for the file attached.
Each line contains the last and first name of a person, the letter S rn N and two integer numbers.
• Print a paper listing of the text file after it has been created,
• Turn this in along with the program that creates the file.
• The final text file should match exactly the listing on the paper provided
Part 2: -
Using functions: Menu for this test
1. Enter data from keyboard (to create the file)
2. Read data from file (send empty structure to the function) (fill it up from the file and send it back to main)
3. Print the report (send the structure with the data to the function to print
4. exit
Read the text from the data file into a structure and print it out, In the listing (print out), print the first name first and then the last name followed by the other data in the same record.
Please can someone explain what should be done !!
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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//system("color F0");
string Last, First;
char code,ch;
int num1;
ofstream data;
ifstream data;
data.open("data. txt");
cout << "Enter Passengers names S(smoking) / N(nonsmoking) and number for data file"<<endl;
cout << "Enter a 'c' to continue and an 'x' to exit" << endl;
cin >> ch;
while (ch != 'x')
{
cout << "Enter the last name: ";
cin >> Last;
cout << ("Enter the first name: ");
cin >> First;
cout << ("Enter S(smoking) or N(nonsmoking): ");
cin >> code;
cout << ("Enter two integers: ");
cin >> num1 ;
cout << ("Enter a 'x' to exit 'c' to continue");
cin >> ch;
//data >> Last >> "," >> First >> "," >> code >> "," >> num1;
}
data.close();
return 0;
cin >> Last;
cout << ("Enter the first name: ");
cin >> First;
cout << ("Enter S(smoking) or N(nonsmoking): ");
cin >> code;
cout << ("Enter two integers: ");
cin >> num1;
cout << ("Enter a 'x' to exit 'c' to continue");
cin >> ch;
//data << Last << "," << First << "," << code << "," << num1 << num2 << endl;
data.close();
return 0;
}
|