You must create a data file for each of these programs and a reasonable set of d
ID: 3558853 • Letter: Y
Question
You must create a data file for each of these programs and a reasonable set of data to adequately test the program. Each Program should contain at least 3 comments, including a comment at the top that includes your name, email address and a 1 line description of the program. Your program should be properly indented and follow a reasonable structure and use meaningful variable names.
Filename: cs201hw1a.cpp A team consist of 3 players. The total weight of a team must be less than 400 pounds. Read in the weight of 3 people, print out each person's weight and the total weight of the team and if the team weighs 400 pounds or less. Your program should work for any number of lines of data. Example Data File 100 200 250 150 140 165 120 140 135
Explanation / Answer
// Filename: cs201hw1a.cpp A team consist of 3 players. The total weight of a team must be less than 400 pounds.
// Read in the weight of 3 people, print out each person's weight and the total weight of the team and if the team weighs 400 pounds or less.
// Your program should work for any number of lines of data.
// Example Data File 100 200 250 150 140 165 120 140 135
#include<iostream>
#include<string>
using namespace std;
int main()
{
ifstream infile("input.txt");
int w1,w2,w3;
if(!infile)
{
cout <<"unable to open file so exiting from program :" << endl;
return 0;
}
while(!infile.eof())
{
infile >> w1 >> w2 >> w3;
if(w1+w2+w2<400)
{
cout << "Weight of persons is " << w1 << " " << w2 << " " << w3 << " Total Weight is " << (w1+w2+w3) << endl;
}
}
infile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.