SlideShare a Scribd company logo
1 of 5
Download to read offline
PFB cpp code for the given problem
#include
#include
#include
#include
#include
#include
using namespace std;
string StringPadding(string original, int charCount )
{
original.resize( charCount, ' ' );
return original;
}
class Song
{
public :
string date;
int wk;
string song;
char Cat;
string artist;
Song(string d, int w, string s, char c, string a)
{
date = d;
wk = w;
song = s;
Cat = c;
artist = a;
}
};
int main()
{
//FILE *fp = freopen("input.txt", "r", stdin);
ifstream fp;
char *fileName = "input.txt";
fp.open(fileName);
if( !fp )
{
cout<<" input file not found  ";
cout<<" Press any key, and enter to terminate and exit the program ";
return 0;
}
int noLinesRead = 0;
string date="", song="", artist="";
int wk;
char cat;
vector vec;
int maxSongLen = 0, maxArtistLen = 0;
while(fp){
fp >> date >> wk;
getline(fp, song);
if(song.length() > maxSongLen) maxSongLen = song.length();
fp >> cat;
getline(fp, artist);
if(artist.length() > maxArtistLen) maxArtistLen = artist.length();
Song sObj = Song(date, wk, song, cat, artist);
vec.push_back(sObj);
}
int maxLengthToBePadded = maxArtistLen + maxSongLen + 17;
string strForEqualSign('=', maxLengthToBePadded);
string strForMinusSign('-', maxLengthToBePadded);
int totalSongs = vec.size();
int femaleArtist = 0;
int maleArtist = 0;
int groupArtist = 0;
float avgWeeks = 0;
int totWeeks = 0;
/* cout << right << StringPadding("Date", 6)
<< StringPadding("Week", 5)
<< StringPadding("Song", maxSongLen+1)
<< StringPadding("Cat", 4)
<< StringPadding("Artist", maxArtistLen)
<< endl; */
cout << setw(5) << right << "Date"
<< setw(5) << right << "Week"
<< setw(maxSongLen/2) << right << "Song"
<< setw(maxSongLen/2 + 1) << right << " "
<< setw(4) << right << "Cat"
<< setw(maxArtistLen/2) << right << "Artist"
<< endl;
cout << strForEqualSign << endl;
for(int i=0; i
Solution
PFB cpp code for the given problem
#include
#include
#include
#include
#include
#include
using namespace std;
string StringPadding(string original, int charCount )
{
original.resize( charCount, ' ' );
return original;
}
class Song
{
public :
string date;
int wk;
string song;
char Cat;
string artist;
Song(string d, int w, string s, char c, string a)
{
date = d;
wk = w;
song = s;
Cat = c;
artist = a;
}
};
int main()
{
//FILE *fp = freopen("input.txt", "r", stdin);
ifstream fp;
char *fileName = "input.txt";
fp.open(fileName);
if( !fp )
{
cout<<" input file not found  ";
cout<<" Press any key, and enter to terminate and exit the program ";
return 0;
}
int noLinesRead = 0;
string date="", song="", artist="";
int wk;
char cat;
vector vec;
int maxSongLen = 0, maxArtistLen = 0;
while(fp){
fp >> date >> wk;
getline(fp, song);
if(song.length() > maxSongLen) maxSongLen = song.length();
fp >> cat;
getline(fp, artist);
if(artist.length() > maxArtistLen) maxArtistLen = artist.length();
Song sObj = Song(date, wk, song, cat, artist);
vec.push_back(sObj);
}
int maxLengthToBePadded = maxArtistLen + maxSongLen + 17;
string strForEqualSign('=', maxLengthToBePadded);
string strForMinusSign('-', maxLengthToBePadded);
int totalSongs = vec.size();
int femaleArtist = 0;
int maleArtist = 0;
int groupArtist = 0;
float avgWeeks = 0;
int totWeeks = 0;
/* cout << right << StringPadding("Date", 6)
<< StringPadding("Week", 5)
<< StringPadding("Song", maxSongLen+1)
<< StringPadding("Cat", 4)
<< StringPadding("Artist", maxArtistLen)
<< endl; */
cout << setw(5) << right << "Date"
<< setw(5) << right << "Week"
<< setw(maxSongLen/2) << right << "Song"
<< setw(maxSongLen/2 + 1) << right << " "
<< setw(4) << right << "Cat"
<< setw(maxArtistLen/2) << right << "Artist"
<< endl;
cout << strForEqualSign << endl;
for(int i=0; i

More Related Content

Similar to PFB cpp code for the given problem#include iostream #include .pdf

lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
DIPESH30
 
C++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdfC++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdf
andreaplotner1
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
ezonesolutions
 
Input output functions
Input output functionsInput output functions
Input output functions
hyderali123
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
anandmobile
 
C basics
C basicsC basics
C basics
MSc CST
 
816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf
sastaindin
 

Similar to PFB cpp code for the given problem#include iostream #include .pdf (20)

C project on a bookshop for saving of coustmer record
C project on a bookshop for saving of coustmer recordC project on a bookshop for saving of coustmer record
C project on a bookshop for saving of coustmer record
 
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
 
C++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdfC++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdf
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Input output functions
Input output functionsInput output functions
Input output functions
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
Write a program with C++ that does the following As noted in the C++ s.docx
Write a program with C++ that does the following As noted in the C++ s.docxWrite a program with C++ that does the following As noted in the C++ s.docx
Write a program with C++ that does the following As noted in the C++ s.docx
 
week-6x
week-6xweek-6x
week-6x
 
7 functions
7  functions7  functions
7 functions
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Unit 3 Input Output.pptx
Unit 3 Input Output.pptxUnit 3 Input Output.pptx
Unit 3 Input Output.pptx
 
Unit2 C
Unit2 C Unit2 C
Unit2 C
 
Unit2 C
Unit2 CUnit2 C
Unit2 C
 
C basics
C basicsC basics
C basics
 
816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf
 
CInputOutput.ppt
CInputOutput.pptCInputOutput.ppt
CInputOutput.ppt
 
Data structures
Data structuresData structures
Data structures
 

More from mailadmin1

WikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdf
WikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdfWikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdf
WikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdf
mailadmin1
 
The period between 30 to 70 years can be defined as midlife. During .pdf
The period between 30 to 70 years can be defined as midlife. During .pdfThe period between 30 to 70 years can be defined as midlife. During .pdf
The period between 30 to 70 years can be defined as midlife. During .pdf
mailadmin1
 
George Washington famous quotes on freedom of speech state that if f.pdf
George Washington famous quotes on freedom of speech state that if f.pdfGeorge Washington famous quotes on freedom of speech state that if f.pdf
George Washington famous quotes on freedom of speech state that if f.pdf
mailadmin1
 
Answer1).TT and TtParental genotypes are TT & Tt and as well .pdf
Answer1).TT and TtParental genotypes are TT & Tt and as well .pdfAnswer1).TT and TtParental genotypes are TT & Tt and as well .pdf
Answer1).TT and TtParental genotypes are TT & Tt and as well .pdf
mailadmin1
 
AnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdf
AnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdfAnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdf
AnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdf
mailadmin1
 

More from mailadmin1 (20)

The percent abundance of beryllium is 2.5 ppm = 0.pdf
                     The percent abundance of beryllium is 2.5 ppm = 0.pdf                     The percent abundance of beryllium is 2.5 ppm = 0.pdf
The percent abundance of beryllium is 2.5 ppm = 0.pdf
 
PO4 -3 Because Higher is the -ve charge,higher .pdf
                     PO4 -3   Because Higher is the -ve charge,higher .pdf                     PO4 -3   Because Higher is the -ve charge,higher .pdf
PO4 -3 Because Higher is the -ve charge,higher .pdf
 
If the pH is in between 1 to 3 it is more acidic .pdf
                     If the pH is in between 1 to 3 it is more acidic .pdf                     If the pH is in between 1 to 3 it is more acidic .pdf
If the pH is in between 1 to 3 it is more acidic .pdf
 
Hydrophobic interactions between the hydrocarbon .pdf
                     Hydrophobic interactions between the hydrocarbon .pdf                     Hydrophobic interactions between the hydrocarbon .pdf
Hydrophobic interactions between the hydrocarbon .pdf
 
Macroevolution1. Huge changes occurs. Examples are adaptive radia.pdf
Macroevolution1. Huge changes occurs. Examples are adaptive radia.pdfMacroevolution1. Huge changes occurs. Examples are adaptive radia.pdf
Macroevolution1. Huge changes occurs. Examples are adaptive radia.pdf
 
Due to longer chain and bounded by OH groups on b.pdf
                     Due to longer chain and bounded by OH groups on b.pdf                     Due to longer chain and bounded by OH groups on b.pdf
Due to longer chain and bounded by OH groups on b.pdf
 
WikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdf
WikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdfWikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdf
WikiLeaks releases 19,252 emails and 8,034 attachments from the top .pdf
 
The treatment modalitites to treat claustrophobia areSolutionT.pdf
The treatment modalitites to treat claustrophobia areSolutionT.pdfThe treatment modalitites to treat claustrophobia areSolutionT.pdf
The treatment modalitites to treat claustrophobia areSolutionT.pdf
 
The period between 30 to 70 years can be defined as midlife. During .pdf
The period between 30 to 70 years can be defined as midlife. During .pdfThe period between 30 to 70 years can be defined as midlife. During .pdf
The period between 30 to 70 years can be defined as midlife. During .pdf
 
larger dispersion forces for H2SeSolutionlarger dispersion for.pdf
larger dispersion forces for H2SeSolutionlarger dispersion for.pdflarger dispersion forces for H2SeSolutionlarger dispersion for.pdf
larger dispersion forces for H2SeSolutionlarger dispersion for.pdf
 
In various cases we required to specify the abstract syntax in the f.pdf
In various cases we required to specify the abstract syntax in the f.pdfIn various cases we required to specify the abstract syntax in the f.pdf
In various cases we required to specify the abstract syntax in the f.pdf
 
An anti-codon is found on tRNA and codes for UGA .pdf
                     An anti-codon is found on tRNA and codes for UGA .pdf                     An anti-codon is found on tRNA and codes for UGA .pdf
An anti-codon is found on tRNA and codes for UGA .pdf
 
Keq = 1(Partial pressure)so2Na2O does not come in the expression .pdf
Keq = 1(Partial pressure)so2Na2O does not come in the expression .pdfKeq = 1(Partial pressure)so2Na2O does not come in the expression .pdf
Keq = 1(Partial pressure)so2Na2O does not come in the expression .pdf
 
it was called as skewed distributionSolutionit was called as.pdf
it was called as skewed distributionSolutionit was called as.pdfit was called as skewed distributionSolutionit was called as.pdf
it was called as skewed distributionSolutionit was called as.pdf
 
George Washington famous quotes on freedom of speech state that if f.pdf
George Washington famous quotes on freedom of speech state that if f.pdfGeorge Washington famous quotes on freedom of speech state that if f.pdf
George Washington famous quotes on freedom of speech state that if f.pdf
 
CSF( cerebrospinal fluid) rhinorrhea is the drainage of fluid surrou.pdf
CSF( cerebrospinal fluid) rhinorrhea is the drainage of fluid surrou.pdfCSF( cerebrospinal fluid) rhinorrhea is the drainage of fluid surrou.pdf
CSF( cerebrospinal fluid) rhinorrhea is the drainage of fluid surrou.pdf
 
color of most salts containing the copper (II) ion impart blue or gr.pdf
color of most salts containing the copper (II) ion impart blue or gr.pdfcolor of most salts containing the copper (II) ion impart blue or gr.pdf
color of most salts containing the copper (II) ion impart blue or gr.pdf
 
Answer1).TT and TtParental genotypes are TT & Tt and as well .pdf
Answer1).TT and TtParental genotypes are TT & Tt and as well .pdfAnswer1).TT and TtParental genotypes are TT & Tt and as well .pdf
Answer1).TT and TtParental genotypes are TT & Tt and as well .pdf
 
AnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdf
AnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdfAnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdf
AnswerTransport of Na+ and K+ mediated by the carrier protein (Na.pdf
 
9P5=9!4!=15120Solution9P5=9!4!=15120.pdf
9P5=9!4!=15120Solution9P5=9!4!=15120.pdf9P5=9!4!=15120Solution9P5=9!4!=15120.pdf
9P5=9!4!=15120Solution9P5=9!4!=15120.pdf
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 

PFB cpp code for the given problem#include iostream #include .pdf

  • 1. PFB cpp code for the given problem #include #include #include #include #include #include using namespace std; string StringPadding(string original, int charCount ) { original.resize( charCount, ' ' ); return original; } class Song { public : string date; int wk; string song; char Cat; string artist; Song(string d, int w, string s, char c, string a) { date = d; wk = w; song = s; Cat = c; artist = a; } }; int main() { //FILE *fp = freopen("input.txt", "r", stdin); ifstream fp; char *fileName = "input.txt";
  • 2. fp.open(fileName); if( !fp ) { cout<<" input file not found "; cout<<" Press any key, and enter to terminate and exit the program "; return 0; } int noLinesRead = 0; string date="", song="", artist=""; int wk; char cat; vector vec; int maxSongLen = 0, maxArtistLen = 0; while(fp){ fp >> date >> wk; getline(fp, song); if(song.length() > maxSongLen) maxSongLen = song.length(); fp >> cat; getline(fp, artist); if(artist.length() > maxArtistLen) maxArtistLen = artist.length(); Song sObj = Song(date, wk, song, cat, artist); vec.push_back(sObj); } int maxLengthToBePadded = maxArtistLen + maxSongLen + 17; string strForEqualSign('=', maxLengthToBePadded); string strForMinusSign('-', maxLengthToBePadded); int totalSongs = vec.size(); int femaleArtist = 0; int maleArtist = 0; int groupArtist = 0; float avgWeeks = 0; int totWeeks = 0; /* cout << right << StringPadding("Date", 6) << StringPadding("Week", 5) << StringPadding("Song", maxSongLen+1) << StringPadding("Cat", 4)
  • 3. << StringPadding("Artist", maxArtistLen) << endl; */ cout << setw(5) << right << "Date" << setw(5) << right << "Week" << setw(maxSongLen/2) << right << "Song" << setw(maxSongLen/2 + 1) << right << " " << setw(4) << right << "Cat" << setw(maxArtistLen/2) << right << "Artist" << endl; cout << strForEqualSign << endl; for(int i=0; i Solution PFB cpp code for the given problem #include #include #include #include #include #include using namespace std; string StringPadding(string original, int charCount ) { original.resize( charCount, ' ' ); return original; } class Song { public : string date; int wk; string song; char Cat; string artist; Song(string d, int w, string s, char c, string a) {
  • 4. date = d; wk = w; song = s; Cat = c; artist = a; } }; int main() { //FILE *fp = freopen("input.txt", "r", stdin); ifstream fp; char *fileName = "input.txt"; fp.open(fileName); if( !fp ) { cout<<" input file not found "; cout<<" Press any key, and enter to terminate and exit the program "; return 0; } int noLinesRead = 0; string date="", song="", artist=""; int wk; char cat; vector vec; int maxSongLen = 0, maxArtistLen = 0; while(fp){ fp >> date >> wk; getline(fp, song); if(song.length() > maxSongLen) maxSongLen = song.length(); fp >> cat; getline(fp, artist); if(artist.length() > maxArtistLen) maxArtistLen = artist.length(); Song sObj = Song(date, wk, song, cat, artist); vec.push_back(sObj); } int maxLengthToBePadded = maxArtistLen + maxSongLen + 17;
  • 5. string strForEqualSign('=', maxLengthToBePadded); string strForMinusSign('-', maxLengthToBePadded); int totalSongs = vec.size(); int femaleArtist = 0; int maleArtist = 0; int groupArtist = 0; float avgWeeks = 0; int totWeeks = 0; /* cout << right << StringPadding("Date", 6) << StringPadding("Week", 5) << StringPadding("Song", maxSongLen+1) << StringPadding("Cat", 4) << StringPadding("Artist", maxArtistLen) << endl; */ cout << setw(5) << right << "Date" << setw(5) << right << "Week" << setw(maxSongLen/2) << right << "Song" << setw(maxSongLen/2 + 1) << right << " " << setw(4) << right << "Cat" << setw(maxArtistLen/2) << right << "Artist" << endl; cout << strForEqualSign << endl; for(int i=0; i