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
Water flows through a converging pipe at a mass flow rate of 25 kg/s. If the inside diameter of the pipes sections are 7.0 cm an
ser-zykov [4K]

Answer:

volumetric flow rate = 0.0251 m^3/s

Velocity in pipe section 1 = 6.513m/s

velocity in pipe section 2 = 12.79 m/s

Explanation:

We can obtain the volume flow rate from the mass flow rate by utilizing the fact that the fluid has the same density when measuring the mass flow rate and the volumetric flow rates.

The density of water is = 997 kg/m³

density = mass/ volume

since we are given the mass, therefore, the  volume will be mass/density

25/997 = 0.0251 m^3/s

volumetric flow rate = 0.0251 m^3/s

Average velocity calculations:

<em>Pipe section A:</em>

cross-sectional area =

\pi \times d^2\\=\pi \times 0.07^2 = 3.85\times10^{-3}m^2

mass flow rate = density X cross-sectional area X velocity

velocity = mass flow rate /(density X cross-sectional area)

velocity = 25/(997 \times 3.85\times10^{-3}) = 6.513m/s

<em>Pipe section B:</em>

cross-sectional area =

\pi \times d^2\\=\pi \times 0.05^2= 1.96\times10^{-3}m^2

mass flow rate = density X cross-sectional area X velocity

velocity = mass flow rate /(density X cross-sectional area)

velocity = 25/(997 \times 1.96\times10^{-3}) = 12.79m/s

7 0
2 years ago
A 179 ‑turn circular coil of radius 3.95 cm and negligible resistance is immersed in a uniform magnetic field that is perpendicu
suter [353]

Answer:

The energy, that is dissipated in the resistor during this time interval is 153.6 mJ

Explanation:

Given;

number of turns, N = 179

radius of the circular coil, r = 3.95 cm = 0.0395 m

resistance, R = 10.1 Ω

time, t = 0.163 s

magnetic field strength, B = 0.573 T

Induced emf is given as;

emf= N\frac{d \phi}{dt}

where;

ΔФ is change in magnetic flux

ΔФ  = BA = B x πr²

ΔФ  = 0.573 x π(0.0395)² = 0.002809 T.m²

emf = N\frac{d \phi}{dt} = 179(\frac{0.002809}{0.163} ) = 3.0848 \ V

According to ohm's law;

V = IR

I = V / R

I = 3.0848 / 10.1

I = 0.3054 A

Energy = I²Rt

Energy = (0.3054)² x 10.1 x 0.163

Energy = 0.1536 J

Energy = 153.6 mJ

Therefore, the energy, that is dissipated in the resistor during this time interval is 153.6 mJ

6 0
3 years ago
A farmer has 12 hectares of land on which he grows corn, wheat, and soybeans. It costs $4500 per hectare to grow corn, $6000 to
maw [93]

The number of hectares of each crop he should plant are; 250 hectares of Corn, 500 hectares of Wheat and 450 hectares of soybeans

<h3>How to solve algebra word problem?</h3>

He grows corn, wheat and soya beans on the farm of 1200 hectares. Thus;

C + W + S = 12   ----(1)

It costs $45 per hectare to grow corn, $60 to grow wheat, and $50 to grow soybeans. Thus;

45C + 60W + 50S = 63750  -----(2)

He will grow twice as many hectares of wheat as corn. Thus;

W = 2C    ------(3)

Put 2C for W in eq 1 and eq 2 to get;

C + 2C + S = 1200

3C + S = 1200     -----(4)

45C + 60(2C) + 50S = 63750

45C + 120C + 50S = 63750

165C + 50S = 63750    ------(5)

Solving eq 4 and 5 simultaneosly gives;

C = 250 and W = 500

Thus; S = 1200 - 3(250)

S = 450

Read more about algebra word problems at; brainly.com/question/13818690

5 0
1 year ago
Where is the Volkswagen super factory located? how is this locate relevant to us?​
Blizzard [7]
It’s in Wolfsburg Germany
4 0
3 years ago
Define and discuss the difference between micronutrients and macronutrients. Also, discuss their importance in the body at rest
almond37 [142]

Answer:

Macronutrients are simply nutrients the body needs in a very high amount e.g Carbohydrate.

MicroNutrients are simply nutrients the body needs but in little amount e.g  Minerals.

Explanation:

So for further breakdown:

What are nutrients? Nutrients are essential elements that nourish the body in different capacities. We as humans get most of out nutrients from the food and water we ingest.

Now about Macro Nutrients: From the prefix "Macro" which means large, we can infer that macro nutrients are elements need by the body for the fundamental processes of the body, deficiency in this nutrients are very easy to spot. Examples are: Carbohydrates, Protein, Fats amd Water.

Micro Nutrients: In relation to macro nutrients this are elements that the body needs but are not needed in Large quantities. They mostly work like supporting nutrients. Most chemical activities like reaction that occur in the body are a function of micro nutrients. Defiencies in micrp nutrients may take some time to spot e.g Minerals and Vitamins

In regards to exercise: Macro nutrients are the essential ones here since they are the ones that generate energy. PS: micro nutrients dont generate energy.

In regards to rest: Both the Macro and Micro Nutrients are essentail for the overall well being of the body.

5 0
3 years ago
Other questions:
  • a. A crude oil pipe’s radius is reduced by 5%. What is the corresponding percentage change in the pressure drop per unit length?
    8·1 answer
  • Which pendulum will.mobe faster​
    13·1 answer
  • The viscosity of all liquids decreases as the temperature is a) Increased b) decreased c) maintained constant d) fluctuating e)
    12·1 answer
  • 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
    5·1 answer
  • You just purchased a 400-L rigid tank for a client who works in the gas industry. The tank is delivered pre-filled with 3 kg of
    8·1 answer
  • #198. Moment of inertia about center of a segmented bar A bar of width is formed of three uniform segments with lengths and area
    7·1 answer
  • Air is to be heated steadily by an 8-kW electric resistance heater as it flows through an insulated duct. If the air enters at 5
    10·1 answer
  • Hii I need help can someone help me
    15·1 answer
  • The insulator is the connection between the grounded circuit conductor and the equipment grounding conductor at the service.
    15·1 answer
  • • Differentiate between laboratory and industrial reactors​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!