Question

In: Computer Science

Given a data file murders.dat containing the number of murders in Hampton roads cities write program...

Given a data file murders.dat containing the number of murders in Hampton roads cities write program code to accomplish the following: 1. Read the data from the murders.dat file and store into parallel arrays or an array of struct 2. Print the total number of murders in the Hampton roads cities 3. Print all of the data read 4. Print the name of the city with the most murders 5. Print the name of the city with the least murders 6. Print the names of all cities with 10 or more murders 7. Print cities sorted by number of murders (lowest to highest)

C++

i just need help with printing the cities sorted by number of murders

Solutions

Expert Solution

/* So as asked above you need helps with only the part 7, I have used buuble sort to sort the structure array*/

#include <iostream>
#include <fstream>
#include <string>
using namespace std;


struct detail
{
  

string city;
  

int n;

};


int
main ()
{
  


string city;
  

int n, i = 0, j = 0;
  


ifstream myfile1 ("murders.dat");
  

while (!myfile1.eof ())
  

{
  
myfile1 >> city >> n;
  
i++;
  
}
  

myfile1.close ();
  

struct detail s[i];
  


ifstream myfile ("murders.dat");
  

if (myfile.is_open ())
  
{
  


while (!myfile.eof ())
  

   {
  

myfile >> city >> n;
  

s[j].city = city;
  

s[j].n = n;
  

j++;
  

}
  
for (int k = 0; k < i - 1; k++)
   {
  
for (int i1 = k + 1; i1 < i; i1++)
   {
  
if (s[k].n > s[i1].n)
       {
      
struct detail temp = s[k];
      
s[k] = s[i1];
      
s[i1] = temp;
      
}
  
}
}
for (int k = 0; k < i; k++)
  
cout << s[k].city << endl;
  
myfile.close ();
  

}
  
else
  
cout << "Unable to open file";
  


return 0;


}



Related Solutions

Write a C++ program to read a data file containing the velocity of cars crossing an...
Write a C++ program to read a data file containing the velocity of cars crossing an intersection. Then determine the average velocity and the standard deviation of this data set. Use the concept of vector array to store the data and perform the calculations. Include a function called “Standard” to perform the standard deviation calculations and then return the value to the main function for printing. Data to use. 10,15,20,25,30,35,40,45,50,55. Please use something basic.
Write a program in Java that reads a file containing data about the changing popularity of...
Write a program in Java that reads a file containing data about the changing popularity of various baby names over time and displays the data about a particular name. Each line of the file stores a name followed by integers representing the name’s popularity in each decade: 1900, 1910, 1920, and so on. The rankings range from 1 (most popular) to 1000 (least popular), or 0 for a name that was less popular than the 1000th name. A sample file...
In java, Write a program that reads a data file containing final exam scores for a...
In java, Write a program that reads a data file containing final exam scores for a class and determines the number of passing scores (those greater than 60) and the number of failing scores (those less than 60). The average score as well as the range of scores should also be determined. The program should request the name of the data file from the end user. The file may contain any number of scores. Using a loop, read and process...
You are given a text file containing a short text. Write a program that 1. Reads...
You are given a text file containing a short text. Write a program that 1. Reads a given text file : shortText.txt 2. Display the text as it is 3. Prints the number of lines 4. Prints the occurences of each letter that appears in the text. [uppercase and lowercase letter is treated the same]. 5. Prints the total number of special characters appear in the text. 6. Thedisplayofstep3,4and5aboveshouldbesaveinanoutputfile:occurencesText.txt write it in C++ programing Language
Write a program that reads a file called document.txt which is a text file containing an...
Write a program that reads a file called document.txt which is a text file containing an excerpt from a novel. Your program should print out every word in the file that contains a capital letter on a new line to the stdout. For example: assuming document.txt contains the text C++
(c++)You will be given a data file containing data for 10 students. The format is as...
(c++)You will be given a data file containing data for 10 students. The format is as follows - grades are double precision numbers: Line 1: Header Information Line 2: Student Full name Line 3: Student ID Line 4: testgrade_1 testgrade_2 testgrade_3 testgrade_4 testgrade_5 Line 5: Student Full name Line 6: Student ID Line 7: testgrade_1 testgrade_2 testgrade_3 testgrade_4 testgrade_5 Line 8: Student Full name Line 9: Student ID Line 10: testgrade_1 testgrade_2 testgrade_3 testgrade_4 testgrade_5 Etc. Read the data into...
Write a Java program that prompts for and reads the number N of cities or locations...
Write a Java program that prompts for and reads the number N of cities or locations to be processed. It then loops N times to prompt for and read, for each location, the decimal latitude, decimal longitude, and decimal magnetic declination. It then computes and displays, for each location, the Qibla direction (or bearing) from Magnetic North. The true bearing from a point A to a point B is the angle measured in degrees, in a clockwise direction, from the...
Write a Fortran program that is able to read in the data file. The file has...
Write a Fortran program that is able to read in the data file. The file has lines with the structure: 19990122 88888 30.5 Where: i) the first is an 8 digit code with the date: yyyymmdd (yyyy is the year, mm is the month, and dd is the day) ii) the second is the five digit odometer reading of a car iii) the third is the amount of fuel put into the car on that date to fill the tank...
write a program in c++ that opens a file, that will be given to you and...
write a program in c++ that opens a file, that will be given to you and you will read each record. Each record is for an employee and contains First name, Last Name hours worked and hourly wage. Example; John Smith 40.3 13.78 the 40.3 is the hours worked. the 13.78 is the hourly rate. Details: the name of the file is EmployeeNameTime.txt Calculate the gross pay. If over 40 hours in the week then give them time and a...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside file there should be items: Open, Save, and Save As. Selecting open prompts the user to input a file name to a txt document containing employee information and displays a Jtable with the information, which can be edited. With column headers {"First Name" , "Last Name" , "Occupation" , "Office #"} Example: Gary Osbourn Teacher 113 Michelle Ramirez Teacher 101 Ava Gomez Principal 120...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT