Language is c++ I need help getting this expected output below i have included m
ID: 3729518 • Letter: L
Question
Language is c++
I need help getting this expected output below i have included my main which is called lab21.cpp and my other file named parsedata .cpp and .h file and a text file
i am not sure how i am supposed to call these functions in my file in order to be able to output my totalticket prices and total wins please show how to do this and be able to run program getting the expected output.
Expected output
text i am adding the total ticket prices and total wins
my .cpp file
my .h file
my main
Sum of ticket price 5 amounts is 280.49 Sum of wins amounts is 47Explanation / Answer
I got the output as expected
ParseData.h
#ifndef FN_H
#define FN_H
#include<iostream>
using namespace std;
struct Team
{
string city;
string team;
double ticketprice;
int wins;
};
void Getsums(string filename,double &TotTicketPrice,int &TotWins);
Team ParseString(string line);
#endif
ParseData.cpp
#include<iostream>
#include<fstream>
#include<sstream>
#include "ParseData.h"
using namespace std;
void Getsums(string filename,double &TotTicketPrice,int &TotWins)
{
string line;
Team x;
ifstream inputfile(filename.c_str());
while(getline(inputfile,line))
{
x=ParseString(line);
TotTicketPrice=TotTicketPrice+x.ticketprice;
TotWins=TotWins+x.wins;
}
}
Team ParseString(string line)
{
Team x;
char comma=',';
istringstream ss(line);
getline(ss,x.city,comma);
getline(ss,x.team,comma);
ss>>x.ticketprice>>comma>>x.wins;
return x;
}
lab21.cpp
#include<iostream>
#include<sstream>
#include "ParseData.cpp"
using namespace std;
int main()
{
double TotTicketPrice=0.0;
int TotWins=0;
string filename="gamedata.txt";
Getsums(filename,TotTicketPrice,TotWins);
cout<<"Sum of ticket price amount is "<<TotTicketPrice<<endl;
cout<<"Sum of wins amounts is "<<TotWins<<endl;
return 0;
}
To compile using g++
g++ lab21.cpp ParseData.cpp -o lab21
To execute
./lab21
Sum of ticket price amount is 280.49
Sum of wins amounts is 47
gamedata.txt
San Francisco,Niners,80.25,2
Dallas,Cowboys,70.00,8
New England,Patriots,63.35,12
chicago,bears,32.40,12
Green Bay,Packers,34.49,13
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.