Question

In: Computer Science

C++ Language Problem 2 (Save and Get Info) : Write a program that asks for the...

C++ Language

Problem 2 (Save and Get Info) : Write a program that asks for the user's name, phone number, and address. The program then saves all information in a data file (each information in one line) named list.txt. Finally, the program reads the information from the file and displays it on the screen  in the following format:

Name: User's Name  
Phone Number: User's Phone Number  
Address: User's Street Address
User's City, State, and Zip Code

Solutions

Expert Solution

Solution

Code

#include <fstream>
#include <iostream>
using namespace std;

int main ()
{
  
char data[100];


ofstream outfile;
outfile.open("list.txt");

cout << "Writing to the file" << endl;
cout << "Enter User name: ";
cin.getline(data, 100);

  
outfile << data << endl;

cout << "Enter your phone number: ";
cin >> data;
cin.ignore();

outfile << data << endl;
cout << "Enter your Address: ";
cin >> data;
cin.ignore();

outfile << data << endl;
cout << "Enter your City: ";
cin >> data;
cin.ignore();

outfile << data << endl;

cout << "Enter your State: ";
cin >> data;
cin.ignore();

outfile << data << endl;

cout << "Enter your zip code: ";
cin >> data;
cin.ignore();

outfile << data << endl;

outfile.close();

ifstream infile;
infile.open("list.txt");

cout << "Reading from the file" << endl;
infile >> data;

cout <<"Name: "<< data << endl;

infile >> data;
cout << "Phone Number: "<<data << endl;

infile >> data;
cout << "Address: "<<data << endl;

infile >> data;
cout <<"City: "<< data << endl;

infile >> data;
cout << "State: "<<data << endl;

infile >> data;
cout <<"Zip Code: "<< data << endl;
infile.close();

return 0;
}

Screenshot

Output

---

all the best


Related Solutions

Problem 2 (Save and Get Info) : Write a program that asks for the user's name,...
Problem 2 (Save and Get Info) : Write a program that asks for the user's name, phone number, and address. The program then saves all information in a data file (each information in one line) named list.txt. Finally, the program reads the information from the file and displays it on the screen  in the following format: Name: User's Name   Phone Number: User's Phone Number   Address: User's Street Address User's City, State, and Zip Code
Using C language: Write a program that asks the user for the size of an array,...
Using C language: Write a program that asks the user for the size of an array, then reads a number of integer values (from user input) into the array. Write a function to print out the array and call it to print the array out after all values are read in. Write a function to implement Insertion Sort and run it on the data array to sort the array. Write another function to implement Selection Sort and run it on...
C language <stdio.h> use double and const Write a program that asks the user for the...
C language <stdio.h> use double and const Write a program that asks the user for the radius of a circle (as a double) and displays the diameter, circumference, and area of the circle. Use a constant of 3.14159 as the value of pi. Have a blank line between the input and the output. Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. The formulas needed are: diameter = 2 * radius circumference = 2 *...
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Problem: Design and write a C language program that can be used as a unit converter...
Problem: Design and write a C language program that can be used as a unit converter application. Your unit converter should contain at least four unit categories, for example: length, mass, temperature, and time. The program should display the main menu that contains unit categories that are available, and the user will be prompted to select a unit category first. After the unit category has been selected the program should then display another menu (i.e., a submenu) that contains at...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a C ++ program that asks the user for the speed of a vehicle (in...
Write a C ++ program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled -------------------------------- 1           40 2           80...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Program specifics: Write a C++ program that does the following: a. Asks the user for the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green and the depth is the diameter of the green, assuming it is circular.) b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge (this club lifts the ball out of rough, sand, etc)....
Write a C++ program that asks for the name and age of three people.   The program...
Write a C++ program that asks for the name and age of three people.   The program should then print out the name and age of each person on a separate line from youngest to oldest. Hint: Start with a program that just asks for the names and ages then prints them out in the same order they are entered. Then modify the program so it prints out the list of names in every possible order.    Note that one of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT