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]
2 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]2 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]2 years ago
5 0
Not really sure sorry for not being able to help
You might be interested in
Lydia is the CEO for a large pharmaceutical manufacturer. Her company is in the final stages of FDA
weqwewe [10]
OSHA inspections are generally unannounced. In fact, except in four exceptional circumstances when advance notice may be given.


It is a criminal offense for any person to give unauthorized advance notice of an OSHA inspection.
5 0
2 years ago
What are the height and width of scissors?
timofeeve [1]
Short ones are 4.5 inches but long ones can be up to 8 inches.
8 0
2 years ago
What’s cat plus cat <br><br><br><br><br><br><br><br> ?
iris [78.8K]
Uhmmmmm, a kitten...? Lol
5 0
3 years ago
Read 2 more answers
Were is carbon monoxide located in a car
Semenov [28]

Answer:

all exhaust gases from all gasoline engines

Explanation:

if u look at the back of ur car when its on u can feel the heat from the exhaust and whT ur feeling is the heat coming from the carbon monoxide gases

6 0
3 years ago
Read 2 more answers
Hey seggsy engineering ppl help me pick out a class ring
aliina [53]

Answer:

I Luv de 2nd one with the silver an black it's out cold no cap

Explanation:

:3 thx 4 de free po..ints luv<3 if ya wanna talk just hit meh up

   -ItzyogurlllllllllLexiiiii<3

7 0
3 years ago
Read 2 more answers
Other questions:
  • Clarifying the issues of a problem is the _____ step in the problem solving process.
    15·1 answer
  • A pump is used to transport water from a reservoir at one elevation to another reservoir at a higher elevation. If the elevation
    5·1 answer
  • Which of the following describes fibers? a)- Single crystals with extremely large length-to-diameter ratios. b)- Polycrystalline
    10·1 answer
  • What is 1000 kJ/sec in watts?
    10·1 answer
  • Infinitivo de vivia kkk xd
    14·1 answer
  • Classify the terms as related to a thermal system or mechanical system.
    8·1 answer
  • The electricity generated by wind turbines annually in kilowatt-hours per year is given in a file. The amount of electricity is
    5·2 answers
  • When a conductor is moved in a magnetic field, a voltage will be induced on the conductor. However, current won't flow through t
    11·1 answer
  • What is stress corrosion cracking?
    9·1 answer
  • Is santa real or nah is santa real or nah
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!