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
List all the qualities of an engineer?
Dennis_Churaev [7]

Answer:

Math and Computer Skills. A qualified engineer should be good at math, at least through the level of calculus and trigonometry, and understand the importance of following the data when making design decisions.

Organization and Attention to Detail.  

Curiosity.  

Creativity.  

Critical Thinking.

Intuition.

Explanation:

6 0
2 years ago
What is the value of the work interaction in this process?
Cloud [144]

Answer:

The answer is "-121\  \frac{KJ}{Kg}".

Explanation:

Please find the correct question in the attachment file.

using formula:

\to W=-P_1V_1+P_2V_2 \\\\When \\\\\to W= \frac{P_1V_1-P_2V_2}{n-1}\ \   or \ \  \frac{RT_1 -RT_2}{n-1}\\\\

W =\frac{R(T_1 -T_2)}{n-1}\\\\

    =\frac{0.287(25 -237)}{1.5-1}\\\\=\frac{0.287(-212)}{0.5}\\\\=\frac{-60.844}{0.5}\\\\=-121.688 \frac{KJ}{Kg}\\\\=-121 \frac{KJ}{Kg}\\\\

7 0
3 years ago
(True/False) Unix is written in the C language. *<br> True<br> O False
Katarina [22]

Answer:

false

Explanation:

8 0
2 years ago
Read 2 more answers
The AGC control voltage: ___________
lyudmila [28]

Answer:

The AGC circuit operates with an input voltage range of 60 dB (5 mV p-p to 5 V p-p), with a fixed output voltage of 250 mV p-p.

Explanation:

3 0
2 years ago
Much of the workd went to bed hungry
Marysya12 [62]
The workers went to bed hungry probably because they are hard workers and so didn’t want to eat because they didn’t want to take break┌(; ̄◇ ̄)┘
7 0
3 years ago
Other questions:
  • A 3-kg block rests on top of a 2-kg block supported by, but not attached to, a spring of constant 40 N/m. The upper block is sud
    14·2 answers
  • A concrete mix design calls for 6.5 sacks of cement, a water/cement ratio of 0.45, and an air content of 2.5%. 1. Complete the m
    13·2 answers
  • Sublimation is to change from
    7·2 answers
  • What are the basic parts of a radio system
    15·1 answer
  • Select the correct answer.
    15·2 answers
  • A private plane pilot is what kind of individual transportation position? professional level mid-level entry-level EPA-certified
    9·1 answer
  • Witch measuring tool would be used to determine the diameter of a crankshaft journal
    5·1 answer
  • What is the condition for maximum efficiency in a DC motor?
    15·1 answer
  • 3. Aqueous cleaners are
    11·1 answer
  • How to plot 0.45 gradation chart for sieve analysis ?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!