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
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...
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...
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)....
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT