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
In javaWrite a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the out
Pavel [41]

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

import java.util.*;

public class FlipCoin

{

public static void main(String[] args)

{

// Declare Scanner

Scanner input = new Scanner (System.in);

int flips;

// Prompt to enter number of toss or flips

System.out.print("Number of Flips: ");

flips = input.nextInt();

if (flips > 0)

{

HeadsOrTails();

}

}

}

public static String HeadsOrTails(Random rand)

{

// Simulate the coin tosses.

for (int count = 0; count < flips; count++)

{

rand = new Random();

if (rand.nextInt(2) == 0) {

System.out.println("Tails"); }

else {

System.out.println("Heads"); }

rand = 0;

}

}

7 0
3 years ago
Refrigerant 134a enters the evaporator of a refrigeration system operating at steady state at -16oC and a quality of 20% at a ve
Dmitry [639]

Answer:

mass flow rate = 0.0534 kg/sec

velocity at exit = 29.34 m/sec

Explanation:

From the information given:

Inlet:

Temperature T_1 = -16^0\ C

Quality x_1 = 0.2

Outlet:

Temperature T_2 = -16^0 C

Quality  x_2 = 1

The following data were obtained at saturation properties of R134a at the temperature of -16° C

v_f= 0.7428 \times 10^{-3} \ m^3/kg \\ \\  v_g = 0.1247 \ m^3 /kg

v_1 = v_f + x_1 ( vg - ( v_f)) \\ \\ v_1 = 0.7428 \times 10^{-3} + 0.2 (0.1247 -(0.7428 \times 10^{-3})) \\ \\  v_1 = 0.0255 \ m^3/kg \\ \\ \\  v_2 = v_g = 0.1247 \ m^3/kg

m = \rho_1A_1v_1 = \rho_2A_2v_2 \\ \\  m = \dfrac{1}{0.0255} \times \dfrac{\pi}{4}\times (1.7 \times 10^{-2})^2\times 6  \\ \\ \mathbf{m = 0.0534 \ kg/sec}

\rho_1A_1v_1 = \rho_2A_2v_2 \\ \\ A_1 =A_2  \\ \\  \rho_1v_1 = \rho_2v_2   \\ \\ \implies \dfrac{1}{0.0255} \times6 = \dfrac{1}{0.1247}\times (v_2)\\ \\ \\\mathbf{\\ v_2 = 29.34 \ m/sec}

3 0
2 years ago
What do you think of this schematic diagram?​
Sholpan [36]

Explanation:

A schematic diagram is a picture that represents the components of a process, device, or other object using abstract, often standardized symbols and lines. ... Schematic diagrams do not include details that are not necessary for comprehending the information that the diagram was intended to convey.

5 0
3 years ago
A gas enters a compressor that provides a pressure ratio (exit pressure to inlet pressure) equal to 8. If a gage indicates the g
olga55 [171]

Answer:

P_2_{abs}=160\ psia (absolute).

Explanation:

Given that

Pressure ratio r

r=8

r=\dfrac{P_2_{abs}}{P_1_{abs}}

  8=\dfrac{P_2_{abs}}{P_1_{abs}}                                  -----1

P₁(gauge) = 5.5 psig

We know that

Absolute pressure = Atmospheric pressure  + Gauge  pressure

Given that

Atmospheric pressure = 14.5 lbf/in²

P₁(abs) = 14.5 + 5.5  psia

P₁(abs) =20 psia

Now by putting the values in the above equation 1

8=\dfrac{P_2_{abs}}{20}

P_2_{abs}=8\times 20\ psia

P_2_{abs}=160\ psia

Therefore the exit gas pressure will be 160 psia (absolute).

7 0
3 years ago
Before you disconnect the service battery from the discharged battery, it is good practice to place a load across the
Lilit [14]

Answer:

it is true i just did this test

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Indicate on a tensile curve such quantities as yield stress, Young's modulus, UTS, toughness, point of necking, point of fractur
    7·1 answer
  • Not much of a question :/ dont answer
    9·1 answer
  • : A pneumatic "cannon" is a device that launches a low mass projectile from a cylindrical tube using pressurized air stored upst
    6·1 answer
  • What does it mean to wire solar cells in parallel vs. wiring them in series? I always get these switched around.​
    10·1 answer
  • 2. When it comes to selling their crop, what are 3 options a farmer has when harvesting their grain?
    5·1 answer
  • Information or signals entered into a computer system is
    10·1 answer
  • 1<br>M<br>A BLIND COOK WHO DEFEATED<br>OVER 30,000 HOME COOKS!<br>y of​
    13·1 answer
  • सत्य से अधिक उपयोगी एवं आज्ञापालन से श्रेष्ठ क्या है ?<br>answer fast plz​
    9·1 answer
  • For the following circuit diagram, if A=010 , B= 101.
    6·1 answer
  • As you push a toggle bolt into a wall, the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!