Accepts the full path to \"lifts.txt\" on the computer as user input. o The prog
ID: 3804358 • Letter: A
Question
Accepts the full path to "lifts.txt" on the computer as user input. o The program should prompt the user for a path until: the file is successfully opened the user types "EXIT" the program should abort if this option is used o Each line of "lifts.txt should contain the following information: contestant name (up to 10 characters long) weight contestant lifted number of repetitions ("reps") performed for each set Uses nested loops to perform the following: number of warriors participating in the contest number of sets performed per contestant total number of reps executed by each contestant o Calculate average weight lifted by all contestants average work performed by all contestants average reps performed by all contestants o Ascertain which contestants have the most strength (highest weight lifted) endurance (most reps performed) capacity (most work performed, work total reps weight) Output all of the above information. please Use C language thanksExplanation / Answer
Hello champ. I coded this for you and tried my best to keep it simple/
#include<iostream>
#include<fstream>
#include<string.h>
using namespace::std;
int main() {
ifstream inFile;
char fileLoc[200];
do {
cout<<"Enter full file path: ";
cin>>fileLoc;
inFile.open(fileLoc);
}while(!inFile.is_open() && strcmp(fileLoc,"exit")!=0);
double avgWt;
string name, maxRepName, maxWtName, maxCapName;
int work, wt, reps, totalReps, set, maxRep=0, maxWt=0, maxCap=0, count = 0, totalWt = 0;
cout<<endl;
cout<<"Name"<<" | "<<"Work"<<" | "<<"Reps"<<" | "<<"Sets"<<endl;
cout<<"---------------------------------------------------- ";
while(inFile>>name) { //read name
count ++; //increase contestAnt count
totalReps = 0; //reset values of individual lifter
set = 0;
inFile>>wt; //read the weight at 2nd column
while(1) {
inFile>>reps;
if(reps == -999) //read reps till -999
break;
totalReps = totalReps + reps; //increase total wt
set ++; //and increase set
}
if (totalReps>maxRep) { //store top scoring lifters
maxRepName=name;
maxRep=totalReps;
}
if (wt>maxWt) { //same here
maxWtName=name;
maxWt=wt;
}
work = wt*totalReps; //calculate work
if (work>maxCap) { //and same here
maxCapName=name;
maxCap=work;
}
totalWt = totalWt + wt; //calc max weight gor future use
cout<<name<<" | "<<work<<" | "<<totalReps<<" | "<<set<<endl; //print each lifter data
}
avgWt = (double)totalWt/count;//calculate avt wt
cout<<endl;
cout<<"Out of "<<count<<"contestants..."<<endl; //and finally print the leaderboard!!
cout<<"Average weight lifted is "<<avgWt<<"lbs ";
cout<<"Strongest lifter "<<maxWtName<<" ("<<maxWt<<"lbs ) ";
cout<<"Most endurance "<<maxRepName<<" ("<<maxRep<<"reps ) ";
cout<<"Most capacity "<<maxCapName<<" ("<<maxCap<<"lbs ) ";
}
Let me know if you face any difficulties solving the the question