Question: C++ Help please. Hello, I am working on this program and I'll detail the parameters for the assignment; 1.) Write a C++ program that stores
C++ Help please.
Hello, I am working on this program and I'll detail the parameters for the assignment;
1.) Write a C++ program that stores data to a text file. The data will be a persons name followed by their age. The program should:
2.)Have a menu that asks the user if they want to see the data in the file or write data to the file.
Have a header file that contains two functions. One gets the data from the file and the other puts the data into the file.
3.)The write data option from the menu should call another function that receives the data from the user. Once the user has finished typing a name it should prompt them for the persons age. These two pieces of information should be stored in a vector as a single string entry delimited by some character of your choice. This function should then pass the vector to the function in the header file that stores the data into the .txt file.
4.)The function in the main that views the data should retrieve the data using the getData function in the header file and then parse each line from the vector using methods of the string class such as str.find() and str.substr(). It should output each line as it reads it. This function should have a void return type. The output should look like this:
Name: Vanna White
Age: 56
I will share the work I have completed so far...
#include
description: This program will take in a persons name and age and store them and be able to read back to the user the name and age of the person */
using namespace std;
void addNaA(); //This function will prompt the user to enter a persons name and age
void viewNaA(); //this function will display the information of the name and ages
int main(int argc, char** argv) { //variables string strChoice = ""; //menu loop while(strChoice !="3") { //main menu cout << " \tMain Menu "; cout << "1. \tAdd Name and Age to File "; cout << "2. \tView Name and Age in File "; cout << "3. \tExit "; cout << "Enter a Choice: "; getline(cin, strChoice); //process user choice if(strChoice=="1") { addNaA(); }else if(strChoice=="2") { viewNaA(); } else if(strChoice !="3") { cout << strChoice << " Please choose an acceptable input. "; } else { cout << "Goodbye."; } }//end main return 0; } void addNaA() { string strName, strAge, strNaA, strFileName; vector
//send vector to SaveData saveData(vNaA,strFileName,true);
} void viewNaA() { //vector to hold returned vector of getData vector
//prompt user for file name cout << "Enter the file name with extension: "; cin >> strFileName; vNaA = getData(strFileName); //dump vector into file //for(char n = 0; n < vNaA.size();n++) // { // if(vNaA.at(n).find(";") == -1) // { // continue; // } //display Name cout << "Name: " << vNaA.at(0).substr(0,5) << endl; //cout << "Age : " < The main hang up I am having is with the number 4. Which is my case is the void viewNaA() function. The struggle seems to be in the str.find() and str.substr(), I am a little lost on how I can separate or parse my vector in two string fields. Many of the examples online are using delimiters and in this example, I am using the ";" delimiter. So the incoming vector is in the format " Vanna White;56 ". Any help on parse this vector out would be great. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
