Question

I need help to do a C++ practice program, please. Write a program that allows the...

I need help to do a C++ practice program, please.

Write a program that allows the user to enter four spring 2020 classes and the credit hours and course cost for each. the class information input by the user should be displayed as seen below:

Enter your four-course codes (with no space) then tab and enter the credit hours and then tab and enter the course cost:

CGS2108   4    399.99

CTS1131    4    449.99

CGS1560   4    449.99

CTS1145   4     399.99

After entering the information above, the program should output the same information entered by the user, and the total credit hours, total course costs, and cost per credit hour as seen below.

Course Code                  Credit Hours                       Course Cost

CGS2108       4      399.99

CTS1131 4                                      449.99

CGS1560                                4                                      449.99

CTS1145                                 4                                      399.99

The program should have two functions prototypes before int main(), and two function definitions after int main () and call each function from within int main().

one function should be an int creditHours with one-dimentional array and a list size as argument, both with int data types. the other function should be a double courseCost with one-dimensional array and a list, both with double data type.

The program must use three arrays, one for string courseCode[4], one for int creditHours [4], and one for double courseCost[4].

after calculate the total credit hours, the total course costs and the cost per credit hour. output the total course costs and the cost per credit hour using two decimal places with setprecision.

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
=================================

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


int calcTotalCreditHours(int creditHours[],int SIZE);
   double calcTotalCourseCost(double courseCost[],int SIZE);
  
int main() {
   const int SIZE=4;
   //Declaring variables
string courseCode[SIZE];
   int creditHours[SIZE];
   double courseCost[SIZE];
   cout<<"Enter Course Codes , credit hoursd course cost"<<endl;
   for(int i=0;i<SIZE;i++)
   {
       cin>>courseCode[i];
   }
   for(int i=0;i<SIZE;i++)
   {
       cin>>creditHours[i];
   }
   for(int i=0;i<SIZE;i++)
   {
       cin>>courseCost[i];
   }
  
   cout<<endl;
   cout<<"Course Code\tCredit Hours\tCourse Cost"<<endl;
   for(int i=0;i<SIZE;i++)
   {
       cout<<courseCode[i]<<"\t\t"<<creditHours[i]<<"\t\t"<<courseCost[i]<<endl;
   }
   int tot=calcTotalCreditHours(creditHours,SIZE);
   double totCourseCost=calcTotalCourseCost(courseCost,SIZE);
  
   cout<<"Total course costs :$"<<totCourseCost<<endl;
   cout<<"Cost per credit hours :$"<<totCourseCost/tot<<endl;
  
  
   return 0;
}
int calcTotalCreditHours(int creditHours[],int SIZE)
{
   int sum=0;
   for(int i=0;i<SIZE;i++)
   {
       sum+=creditHours[i];
   }
   return sum;
}
   double calcTotalCourseCost(double courseCost[],int SIZE)
   {
       double sum=0;
       for(int i=0;i<SIZE;i++)
       {
           sum+=courseCost[i];
       }
       return sum;
   }

===============================

Output:

==========================Thank You

Add a comment
Know the answer?
Add Answer to:
I need help to do a C++ practice program, please. Write a program that allows 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
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