Question

Write a program in c++ that ask a user for following information AgentID an Int Price...

Write a program in c++ that ask a user for following information AgentID an Int Price a float HouseType a string write the information to a file named AgentComission.txt and then read that information from file and display it on screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<fstream>

using namespace std;

int main() {

ofstream outputFile;
outputFile.open ("AgentComission.txt");
int AgentID ;
float Price ;
string HouseType ;
cout<<"Enter the AgentID: ";
cin >> AgentID;
cout<<"Enter the Price: ";
cin >> Price;
cout<<"Enter the HouseType: ";
cin >> HouseType;
outputFile<<AgentID<<"\t"<<Price<<"\t"<<HouseType;
cout<<"File has been generated"<<endl;
outputFile.close();
ifstream inputFile;
inputFile.open("AgentComission.txt");

cout<<"Reading file contents from a file"<<endl;
if (inputFile.is_open()) {
while (!inputFile.eof()) {


inputFile >> AgentID>>Price>>HouseType;
cout<<"AgentID: "<<AgentID <<endl;
cout<<"Price: "<<Price <<endl;
cout<<"HouseType: "<<HouseType <<endl;


}
}
outputFile.close();
inputFile.close();
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                            

sh-4.2$ main                                                                                                                                                                                         

Enter the AgentID: 2222                                                                                                                                                                              

Enter the Price: 5000                                                                                                                                                                                

Enter the HouseType: Residentials                                                                                                                                                                    

File has been generated                                                                                                                                                                              

Reading file contents from a file                                                                                                                                                                    

AgentID: 2222                                                                                                                                                                                        

Price: 5000                                                                                                                                                                                          

HouseType: Residentials

Add a comment
Know the answer?
Add Answer to:
Write a program in c++ that ask a user for following information AgentID an Int Price...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C++ program to ask the user to inter two integers and the program...

    Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Enter two integers 18 27 The GCD is = 9

  • Write program in C. Please ask the user to determine how many numbers to enter, and...

    Write program in C. Please ask the user to determine how many numbers to enter, and then find and display the largest one with two digits. Please call the following two functions in your main functions. void input_numbers(float *data, int num); void find_largest(float *data, int num); Note: In this assignment, please save the entered numbers using pointer, pass the pointer as the arguments. Depending upon the number of elements, the required size is allocated which prevents the wastage of memory....

  • Write a complete C++ program to ask the user to inter two integers and the program...

    Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Enter two integers 18 27 The GCD is = 9

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • 3. Write a C# program that perform the following operations (30 points) (1) ask the user...

    3. Write a C# program that perform the following operations (30 points) (1) ask the user to input a string (2) find out the length of the string (3) convert the string into lowercase (5) Display the string by applying PadLeft

  • Write the program in C The following statistics for cities of the Vege country are stored...

    Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...

  • Write a program that displays a menu on the screen. The menu will give the user...

    Write a program that displays a menu on the screen. The menu will give the user four options - enter two integers, enter two decimal numbers (#.#), enter one integer and one decimal number, or quit. The inputs should be labelled a, b, c, or d, and you should enter in the letter to choose the appropriate option. Once the user selects the option, two numbers will be read in from the user. The numbers will be added together and...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • write a program that defines two different structures as follows: 1) A cPu structure that contains...

    write a program that defines two different structures as follows: 1) A cPu structure that contains a manufacturers Name (string), a model number (int), a speed (float), and a price (float). a model number (int), 2) A Motherboard structure that contains a manufacturer's ID (int), and a price (float). Your program use arrays of each type of structure. All arrays wi contain a total of five will structures. Your program will also read in two separate files. You can obtain...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT