Im trying to write a program that will get 10 different houses information about those houses will be price square feet and rooms. I have to use an infile about the information and then have it sort by selection or bubble sort also use a header file, can anyone help me out with how to make one.

Recommended Answers

All 4 Replies

Have you written anything yet? If so, post it here and we'll help you where you have specific problems. If not, write something and come back with specific questions on where you're having trouble.

I have to read this information from a .txt file

Dan 4 25000 80000
Joe 2 11000 15000
Nicolas 5 220000 1200000
Chris 3 45000 125000
Michael 6 34540 800000
Silvia 3 60000 130000
Shawn 4 53000 250000
Mike 1 9000 30000
Jeffery 4 45000 75000
Jessica 3 65000 55000

so I read this from a file. The names are owners of a house, how many bedrooms, square feet, and price.I have to sort the names by linear seach and the rest by bubble sort and create an outfile with all the different orders. this is what I have so far I dunno If I am on the right track.

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

int main () 
{
  string array[10];                         // creates array to hold names

  string line;                              //this will contain the data read from the file
  ifstream myfile ("C:\\users\\michael\\documents\\example.txt");          //opening the file.

      getline (myfile,line);                //get one line from the file
      cout << line <<  endl;                //and output it
      array[0] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[1] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[2] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[3] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl;
      array[4] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[5] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[6] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[7] = line;
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[8] = line; 
      getline (myfile,line);                //get one line from the file
      cout << line <<  endl; 
      array[9] = line;




    myfile.close();                         //closing the file





       system("PAUSE");
  return 0; 
}

string arr[10];

".I have to sort the names by linear seach and the rest by bubble sort and create an outfile with all the different orders"
I can't understand it, what do you mean be "sort by linear search"!!, do you mean insertion sort or what?
any way, have you thought about using the STL (Standard Template Library), bec. it will be mush easier?

I have to assign the names in order from A-Z

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.