// Function without repeated modules
float calcFees(int numModules, float moduleFee) {
return numModules * moduleFee;
}
// Function with repeated modules
float calcFees(int numModules, float moduleFee, int numRepeatedModules, float repeatedModuleFee) {
return (numModules * moduleFee) + (numRepeatedModules * repeatedModuleFee);
}
int main() {
int numModules, numRepeatedModules;
float moduleFee, repeatedModuleFee;
std::cout << "Does the student repeat any modules? (0 = No, 1 = Yes): ";
int repeatModules;
std::cin >> repeatModules;
std::cout << "Enter the number of modules enrolled for the first time: ";
std::cin >> numModules;
std::cout << "Enter the fee for those modules: ";
std::cin >> moduleFee;
, float totalFees;
if (repeatModules == 0) {
totalFees = calcFees(numModules, moduleFee);
} else {
std::cout << "Enter the number of modules repeated: ";
std::cin >> numRepeatedModules;
std::cout << "Enter the fee for the repeated modules: ";
std::cin >> repeatedModuleFee;
1. The program starts by including the necessary header file iostream, which allows us to work with
input and output streams in C++.
2. The first overloaded function calcFees is declared with two parameters: int numModules and float
moduleFee. This function calculates the tuition fees when there are no repeated modules. It
multiplies the number of modules by the fee for each module and returns the total fees.
3. The second overloaded function calcFees is declared with four parameters: int numModules, float
moduleFee, int numRepeatedModules, and float repeatedModuleFee. This function calculates the
tuition fees when there are repeated modules. It calculates the fees for the modules taken for the
first time using the same logic as the previous function, and then adds the fees for the repeated
modules. The total fees are returned.
4. The main function is defined, which is the entry point of the program.
5. Inside the main function, the necessary variables are declared to store the user input:
numModules, numRepeatedModules, moduleFee, and repeatedModuleFee.
6. The user is prompted to enter whether the student repeats any modules, and the value is stored in
the repeatModules variable.
7. Next, the user is asked to input the number of modules enrolled for the first time (numModules)
and the fee for those modules (moduleFee).
8. Based on the value of repeatModules, the appropriate overloaded function is called to calculate
the tuition fees. If the student doesn't repeat any modules, the first calcFees function is used;
otherwise, the second calcFees function is used.
9. If the user entered that the student repeats modules, the program prompts for the number of
repeated modules (numRepeatedModules) and the fee for those modules (repeatedModuleFee).
10. The total fees are calculated by assigning the result of the calcFees function call to the totalFees
variable.
11. Finally, the total tuition fees are displayed to the user using std::cout.
The two overloaded functions are calcFees. One version accepts the number of modules and fee for the
modules enrolled for the first time, while the other version accepts additional parameters for the number
of repeated modules and fee for those repeated modules.
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Learn2Progress. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $5.74. You're not tied to anything after your purchase.