Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how would you go about setting this problem up? Write the declarations for an ar

ID: 3690148 • Letter: H

Question

how would you go about setting this problem up?

Write the declarations for an array of structs that can be used to store all the top 10 hits for every week of the year. Assume that the data stored for each hit is the title, artist, production company, cost, and month of issue (an integer). Write the following functions: Load the array with data from a data file. For testing purposes, use just five weeks. Display the top hit for every week of the year. Display the number of weeks each #1 hit has been #1. For a particular recording, determine how many weeks it has been #1, #2, and so on. For a particular hit, determine how many weeks it has been on the top 10 list. For a particular artist, determine how many weeks that artist has had n recordings on the top 10 list, where n is a function parameter.

Explanation / Answer

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

//hit structure
struct hit{
string Title;
string Artist;
};

//fxn to load array of struct with data from file
void load(hit list[],int size){
ifstream infile("TopHits.txt");
for(int i=0;i<size && !infile.eof();i++){
infile>>list[i].Title>>list[i].Artist;
}
return;
}

void DisplayTopHit(hit list[],int size){
cout<<"Week Title Artist ";
for(int i=0;i<size;i+=10){
cout<<(i/10)<<" "<<list[i].Title<<" "<<list[i].Artist<<endl;
}
}


int main(){
const int WEEKS=520;
hit WeeklyTen[WEEKS];
load(WeeklyTen,WEEKS);
DisplayTopHit(WeeklyTen,WEEKS);
cin.ignore();
cin.get();
return 0;
}