Question
c++
When the students started selling cookies, they were told that the students who sell the maximum number of bóxes will have 10
Ch5_Ex19Data.txt 1 3.50 2 Sara 120 3 Lisa 128 4 Cindy 359 5 Nicole 267 6 Brook 450 7 Blair 165 8 Abby 290 9 Amy 190 10 Megan
2 #include <iostream> 3 #include <fstream> 4 #include <string> 5 #include <iomanip> 7 using namespace std; 9 int main() 10 {
cout << fixed << showpoint << setprecision(2); cout << Processing data. << endl; totalNumOfBoxesSold = 0; numofVolunteers =
numOfVolunteers++; inFile >> name; cout << endl; cout << The total number of boxes sold: . << totalNumOfBoxesSoldk<< endl;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Ch5_Ex19Data.txt

3.50
Sara 120
Lisa 128
Cindy 359
Nicole 267
Brook 450
Blair 165
Abby 290
Amy 190
Megan 450
Eligabeth 280
Meridth 290
Lesile 430
Chelsea 378
Katie 450
Jill 350

____________________

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;


int findMaxBoxesSold(int boxes[],int cnt);
double displayStudentsSoldMaxBoxes(string names[],int boxes[],int cnt,int maxBoxesCnt,double costOfOneBox);
int main() {
   //Declaring variables
string name;
   int numOfVolunteers;
   int numOfBoxesSold;
   int totalNumOfBoxesSold;
   double costOfOneBox;
   int cnt=0;
  
   ifstream infile;
   infile.open("Ch5_Ex19Data.txt");
  
   if(!infile)  
   {
       cout<<"Unavle to open the input file.The Program Terminates!"<<endl;
       return 1;
   }
   else
   {
       cout<<fixed<<showpoint<<setprecision(2);
      
       totalNumOfBoxesSold=0;
       numOfVolunteers=0;
      
       infile>>costOfOneBox;
       while(infile>>name>>numOfBoxesSold)
       {
   cnt++;      
       }
       infile.close();
      
       string* names=new string[cnt];
       int* boxes=new int[cnt];
      
           infile.open("Ch5_Ex19Data.txt");
          
               infile>>costOfOneBox;;
              
           for(int i=0;i<cnt;i++)
           {
               infile>>name>>numOfBoxesSold;
               names[i]=name;
               boxes[i]=numOfBoxesSold;
           }
      
       infile.close();
      
       int maxBoxesCnt=findMaxBoxesSold(boxes,cnt);
       double amtDonated=displayStudentsSoldMaxBoxes(names,boxes,cnt,maxBoxesCnt,costOfOneBox);
       cout<<"The Amount that will be donated to their favorite charitable organization :"<<amtDonated<<endl;
   }
   return 0;
}
int findMaxBoxesSold(int boxes[],int cnt)
{
   int max=boxes[0];
   for(int i=0;i<cnt;i++)
   {
       if(max<boxes[i])
       {
           max=boxes[i];
       }
   }
   return max;
}
double displayStudentsSoldMaxBoxes(string names[],int boxes[],int cnt,int maxBoxesCnt,double costOfOneBox)
{
   double amountDonated=0;
   cout<<"Displaying the Student names who sold maximum no of boxes :"<<endl;
   for(int i=0;i<cnt;i++)
   {
       if(boxes[i]==maxBoxesCnt)
       {
           cout<<names[i]<<endl;
           amountDonated+=(boxes[i]*costOfOneBox)*0.10;
       }
  
   }
   return amountDonated;
}

___________________________

Output:

- C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\ReadFileStudentNamesNoofBoxesSoldCalculateAmountDonatedToCharitableOrg.exe Displ


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
c++ When the students started selling cookies, they were told that the students who sell the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program...

    PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...

  • 4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std;...

    4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

  • Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo t...

    Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

  • Write a simple telephone directory program in C++ that looks up phone numbers in a file...

    Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...

  • I Need Help. I MUST USED VECTOR OF STRUCTUERS INSTEAD OF AN ARRAY. HOW CAN MAKE...

    I Need Help. I MUST USED VECTOR OF STRUCTUERS INSTEAD OF AN ARRAY. HOW CAN MAKE THIS INTO VECTOR STRUCTUERS? #include #include using namespace std; // This program demonstrates how to use an array of structures// PLACE YOUR NAME HERE // Fill in code to define a structure called taxPayer that has three// members: taxRate, income, and taxes -- each of type float int main(){   // Fill in code to declare an array named citizen which holds   // 5 taxPayers structures cout...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT