1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aliya0001 [1]
3 years ago
13

Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the curr

ent directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or all code is in main() will result in a grade submission of 0. List of names in Names.txt: Jackie Sam Bill Tom Mary Paul Zev Barb John Sharon Dana Dominic Steven Padro Katey Kathy Darius Angela Mimi Jesse Kenny Lynn Hector Brittany Jenn Joe Chloe Geena Sylvia Dean
Engineering
2 answers:
Katen [24]3 years ago
7 0

Answer: This doesn't work fully, but it's a start. Good Luck

#include <iostream>

#include <fstream>

#include <string>

#include <cstdlib>

using namespace std;

class People

{

private:

const static int SIZE = 30;  

string names[SIZE];  

int birth_years[SIZE];  

int count;  

void sort();  

void display();  

public:

People();

void simulate();

};

People::People()

{

count = 0;

// open both files

ifstream namesFile, birthyearsFile;

namesFile.open("Names.txt");

birthyearsFile.open("BirthYear.txt");

while (!namesFile.eof() && !birthyearsFile.eof() && count < SIZE)

{

 getline(namesFile, names[count]);  

 birthyearsFile >> birth_years[count];  

 count++;  

}

// files open failed, exit the program

if (namesFile.fail() || birthyearsFile.fail())

{

 cout << "Unable to open input file(s). Terminating" << endl;

 exit(1);

}

//close the files

namesFile.close();

birthyearsFile.close();

sort();

display();

}

void People::sort()

{

for (int i = 0; i < count - 1; i++)

{

 for (int j = 0; j < count - 1 - i; j++)

 {

  if (names[j] > names[j + 1])

  {

   string tempName = names[j];

   names[j] = names[j + 1];

   names[j + 1] = tempName;

   int tempYear = birth_years[j];

   birth_years[j] = birth_years[j + 1];

   birth_years[j + 1] = tempYear;

  }

 }

}

}

void People::display()

{

cout << "Alphabetical Roster of Names: " << endl;

for (int i = 0; i < count; i++)

{

 cout << names[i] << "\t" << birth_years[i] << endl;

}

cout << endl;

}

void People::simulate()

{

int year;

cout << endl << "Names by Birth Year" << endl;

// input the birth year

cout << "Please enter the birth year: ";

cin >> year;

// loop that continues until valid input has been read

while (cin.fail() || year < 1995 || year > 2005)

{

 cin.clear();  

 cin.ignore(100, '\n');  

 cout << "Invalid birth year entered, try again: ";  

 cin >> year;

}

bool found = false;  

for (int i = 0; i < count; i++)

{

 if (birth_years[i] == year)  

 {

  if (!found)  

  {

   cout << endl << "For the birth year of " << year << ":" << endl;

   found = true;

  }

  // display the name

  cout << names[i] << endl;

 }

}

// no name with birth year found

if (!found)

 cout << endl << "No names with the birth year " << year << "." << endl;

cout << "End of results" << endl;

}

int main()

{

People people;  

people.simulate();  

return 0;

}

Explanation:

Tanzania [10]3 years ago
5 0
Not really sure sorry for not being able to help
You might be interested in
Manufacturers frequently make choices about their suppliers of raw materials based on their impact on society and the environmen
love history [14]
Manufacturers seek attention
4 0
3 years ago
Which option identifies the goal in the user story in the following scenario?
Naddika [18.5K]

Answer:<u>     to purchase organic jams</u>

Explanation:

I think it is

3 0
3 years ago
Read 2 more answers
In primary processing their are 3 different steps, what are the steps?
Nana76 [90]

Answer:

Primary processing involves cutting, cleaning, packaging, storage and refrigeration of raw foods to ensure that they are not spoilt before they reach the consumer.

8 0
3 years ago
If the reading of mercury manometer was 728 mmHg, what is the reading for another liquid such as water in mH20 units?​
vodka [1.7K]

Answer:

mH275 units

Explanation:

  • that was true
4 0
3 years ago
1. A flywheel is suspended by resting the inside of the rim on a horizontal knife edge so that the wheel can swing in a vertical
sammy [17]

Answer: A fly wheel having a mass of 30kg was allowed to swing as pendulum about a knife edge at inner side of the rim as shown in figure.

Explanation:

8 0
3 years ago
Other questions:
  • Write a program that asks the user to input a vector of integers of arbitrary length. Then, using a for-end loop the program exa
    13·1 answer
  • Tell me a riddle and whoevers i like best gets brainliest
    6·1 answer
  • If you are setting up a race car. What is the cross weight? Does it matter?
    5·1 answer
  • Water enters a centrifugal pump axially at atmospheric pressure at a rate of 0.12 m3
    10·1 answer
  • A mixture of octane, C8H18, and air flowing into a combustor has 60% excess air and 1 kmol/s of octane. What is the mole flow ra
    11·1 answer
  • Which feature would be used to measure OUTER diameter?
    15·1 answer
  • Which of the following relationship types most closely resembles the relationship between the national importance of residential
    15·1 answer
  • What regulates the car engines temperature
    10·2 answers
  • What is the approximate Brinell hardness of a 1040 steel having a yield strength of 620 MPa (90,000 psi)
    13·1 answer
  • Need help<br> What is elasticity?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!