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

Write the declarations for an array of structs that can be used to store all the

ID: 3547060 • Letter: W

Question

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. The data for the first six weeks of 2012 is stored in a text file (TopHits.txt) that is supplied to you. Each line in the file contains the song title followed by a | followed by the artist. The first 10 records are the hits for the first week (from 1 to 10), the next 10 records are the hits for the next week and so on. Write functions to:

1.     Load the array of structs with data from the file.

2.     Display the top hit for every week of the year.

You will be supplied with an input file, TopHits.txt, formatted as described above. If you are using Cygwin, place the input files in the same directory as your source code. If you are using NetBeans, place them in your project folder.

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. The data for the first six weeks of 2012 is stored in a text file (TopHits.txt) that is supplied to you. Each line in the file contains the song title followed by a | followed by the artist. The first 10 records are the hits for the first week (from 1 to 10), the next 10 records are the hits for the next week and so on. Write functions to: Load the array of structs with data from the file. Display the top hit for every week of the year. You will be supplied with an input file, TopHits.txt, formatted as described above. If you are using Cygwin, place the input files in the same directory as your source code. If you are using NetBeans, place them in your project folder.

Explanation / Answer

//please rate fairly


#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;

}