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
declare integer product declare integer number product = 0 do while product &lt; 100 display ""Type your number"" input number p
Brilliant_brown [7]

Full Question

1. Correct the following code and

2. Convert the do while loop the following code to a while loop

declare integer product

declare integer number

product = 0

do while product < 100

display ""Type your number""

input number

product = number * 10

loop

display product

End While

Answer:

1. Code Correction

The errors in the code segment are:

a. The use of do while on line 4

You either use do or while product < 100

b. The use of double "" as open and end quotes for the string literal on line 5

c. The use of "loop" statement on line 7

The correction of the code segment is as follows:

declare integer product

declare integer number

product = 0

while product < 100

display "Type your number"

input number

product = number * 10

display product

End While

2. The same code segment using a do-while statement

declare integer product

declare integer number

product = 0

Do

display "Type your number"

input number

product = number * 10

display product

while product < 100

4 0
3 years ago
Frank D. Drake, an investigator in the SETI (Search for Extra-Terrestrial Intelligence) program, once said that the large radio
AlexFokin [52]

Answer:

attached below

Explanation:

4 0
3 years ago
Isn't this website cheating?
Orlov [11]

Answer: What website?

Explanation:

8 0
3 years ago
Read 2 more answers
calculate how much black eyes seeds are necessary to plant a 6- hectare( 14.425 acres) field. given that the weight of 1000 blac
11111nata11111 [884]

Answer: 1.38g

Explanation:

Width of planting area = 100m

Field size = 6-hectares(14.425 acres)

Weight of 1000 black eye seed = 230g

1 lb = 453.4g

1 black eye seed = 230g/1000 = 0.23g = 0.00023kg

1 hectare = 10,000sq metre

6 hectare = 60,000sq metre

(Weight/Area) kg/m2

0.00023kg / 10,000 = 2.3×10^-8kg/m^2

And field size = 6hectares = 60,000m^2

(2.3×10^-8) × 60,000 = 0.00138kg of black eye seed

0.00138kg × 1000 = 1.38g

6 0
3 years ago
A power cycle receives QH by heat transfer from a hot reservoir at TH = 1200 K and rejects energy QC by heat transfer to a cold
PIT_PIT [208]

Answer:

a) Irreversible, b) Reversible, c) Irreversible, d) Impossible.

Explanation:

Maximum theoretical efficiency for a power cycle (\eta_{r}), no unit, is modelled after the Carnot Cycle, which represents a reversible thermodynamic process:

\eta_{r} = \left(1-\frac{T_{C}}{T_{H}} \right)\times 100\,\% (1)

Where:

T_{C} - Temperature of the cold reservoir, in Kelvin.

T_{H} - Temperature of the hot reservoir, in Kelvin.

The maximum theoretical efficiency associated with this power cycle is: (T_{C} = 400\,K, T_{H} = 1200\,K)

\eta_{r} = \left(1-\frac{400\,K}{1200\,K} \right)\times 100\,\%

\eta_{r} = 66.667\,\%

In exchange, real efficiency for a power cycle (\eta), no unit, is defined by this expression:

\eta = \left(1-\frac{Q_{C}}{Q_{H}}\right) \times 100\,\% = \left(\frac{W_{C}}{Q_{H}} \right)\times 100\,\% = \left(\frac{W_{C}}{Q_{C} + W_{C}} \right)\times 100\,\% (2)

Where:

Q_{C} - Heat released to cold reservoir, in kilojoules.

Q_{H} - Heat gained from hot reservoir, in kilojoules.

W_{C} - Power generated within power cycle, in kilojoules.

A power cycle operates irreversibly for \eta < \eta_{r}, reversibily for \eta = \eta_{r} and it is impossible for \eta > \eta_{r}.

Now we proceed to solve for each case:

a) Q_{H} = 900\,kJ, W_{C} = 450\,kJ

\eta = \left(\frac{450\,kJ}{900\,kJ} \right)\times 100\,\%

\eta = 50\,\%

Since \eta < \eta_{r}, the power cycle operates irreversibly.

b) Q_{H} = 900\,kJ, Q_{C} = 300\,kJ

\eta = \left(1-\frac{300\,kJ}{900\,kJ} \right)\times 100\,\%

\eta = 66.667\,\%

Since \eta = \eta_{r}, the power cycle operates reversibly.

c) W_{C} = 600\,kJ, Q_{C} = 400\,kJ

\eta = \left(\frac{600\,kJ}{600\,kJ + 400\,kJ} \right)\times 100\,\%

\eta = 60\,\%

Since \eta < \eta_{r}, the power cycle operates irreversibly.

d) Since \eta >  \eta_{r}, the power cycle is impossible.

8 0
3 years ago
Other questions:
  • Consider a very long rectangular fin attached to a flat surface such that the temperature at the end of the fin is essentially t
    8·1 answer
  • How many electrons move past a fixed reference point every t = 2.55 ps if the current is i = 7.3 μA ? Express your answer as an
    5·1 answer
  • (8 points) Consider casting a concrete driveway 40 feet long, 12 feet wide and 6 in. thick. The proportions of the mix by weight
    8·1 answer
  • Consider a drainage basin having 60% soil group A and 40% soil group B. Five years ago the land use pattern in the basin was ½ w
    12·1 answer
  • What is the uncertainty in position of an electron of an atom if there is t 2.0 x 10' msec uncertainty in its velocity? Use the
    12·1 answer
  • Write a program that uses while loops to perform the following steps: Step a: Prompt the user to input two integers: firstNum an
    12·1 answer
  • Consider a steady-state experiment in which the observed current due to reduction of Ox to R is 85 mA/cm2. What is the concentra
    12·1 answer
  • 4. Two technicians are discussing the evaporative emission monitor. Technician A says that serious monitor faults cause a blinki
    14·1 answer
  • (25) Consider the mechanical system below. Obtain the steady-state outputs x_1 (t) and x_2 (t) when the input p(t) is the sinuso
    9·1 answer
  • state &amp; prove parallelogram law of vector addition &amp;Also determine magnitude &amp;direction of resultant vector.​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!