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
The critical resolved shear stress for a metal is 39 MPa. Determine the maximum possible yield strength (in MPa) for a single cr
damaskus [11]

Answer:

78 MPa

Explanation:

Given that the critical resolved shear stress for a metal is 39 MPa, the maximum possible yield strength for a single crystal of this metal is twice the critical resolved shear stress for the metal. The maximum yield yield strength for a single crystal of this metal that is pulled in tension (\sigma_y) is given as:

\sigma_y=2*critical\ resolved\ shear\ stress(\tau_{css})\\\\\sigma_y=2*\tau_{css}\\\\\sigma_y=2*39\\\\\sigma_y=78\ MPa

4 0
3 years ago
Which of the following are some of the problems found in city streets?
storchak [24]

Answer: drugs and rushing cars

Explanation: drug dealers are everywhere on city streets nowadays they have been killing young adults

rushing cars or reckless drivers cut curb fast and potentially someone can get hurt they are speeding and not worrying about other people lives at stake

4 0
3 years ago
Need some help with these plz
pashok25 [27]

100: D, third law of motion

101: D, second law of motion

5 0
3 years ago
4. The outer end of a control arm is attached to the steering knuckle through a
arlik [135]
Is attached to the spring
3 0
3 years ago
Read 2 more answers
At a certain location, wind is blowing steadily at 10 m/s. Determine the mechanical energy of air per unit mass and the power ge
tangare [24]

Answer:

e= 50 J/kg

Explanation:

Given that

Speed ,v= 10 m/s

Diameter of the turbine = 90 m

Density of the air ,ρ = 1.25 kg/m³

We know that mechanical energy given as

E=\dfrac{1}{2}mv^2\ J

That is why mechanical energy per unit mass will be

e=\dfrac{1}{2}v^2\ J/kg

Now by putting the values in the above equation we get

e=\dfrac{1}{2}\times 10^2\ J/kg

e= 50 J/kg

That why the mechanical energy unit mass will be 50 J/kg.

5 0
3 years ago
Other questions:
  • Who does the narrator blame for the loss of her job as editor-in-chief? <br> see if i care readworks
    8·2 answers
  • Suppose that a wireless link layer using a CSMA-like protocol backs off 1ms on average. A packet’s link and physical layer heade
    5·1 answer
  • Describe three advantages and three disadvantages of JIT?
    12·1 answer
  • A rigid tank contains an ideal gas at 40°C that is being stirred by a paddle wheel. The paddle wheel does 240 kJ of work on the
    9·1 answer
  • The waffle slab is: a) the two-way concrete joist framing system. b) a one-way floor and roof framing system. c) the one-way con
    11·1 answer
  • The rate at which velocity changes is called?
    5·2 answers
  • An aggregate blend is composed of 65% coarse aggregate by weight (Sp. Cr. 2.635), 36% fine aggregate (Sp. Gr. 2.710), and 5% fil
    5·1 answer
  • Decide whether the function is an exponential growth or exponential decay function, and find the constant percentage rate of gro
    10·1 answer
  • Which of the following parts tells the transmission how fast or slowly a vehicle is going? A) pump
    5·1 answer
  • Liquefied Natural Gas (LNG) is a natural gas in its liquid form that is clear, colorless, odorless, non-corrosive, and non-toxic
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!