Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Overig

COS1512 Assignment 2 Year 2023 Solutions + Output + Explaination

Beoordeling
-
Verkocht
-
Pagina's
19
Geüpload op
17-07-2023
Geschreven in
2022/2023

Complete Solutions to COS1512 Assignment 2 for the year 2023. Includes Code, Output of run-time, and Explaination.

Instelling
Vak

Voorbeeld van de inhoud

UNISA
Assignment 2
COS1512

, Question 1:
Output:

No repeated course Output:




With Repeated courses:




Code:

//COS1512 - Assignment 2 2023 Question 1
#include <iostream>

// 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;

totalFees = calcFees(numModules, moduleFee, numRepeatedModules, repeatedModuleFee);
}

std::cout << "Total tuition fees: " << totalFees << std::endl;

return 0;
}

Explanation:

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.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
17 juli 2023
Aantal pagina's
19
Geschreven in
2022/2023
Type
OVERIG
Persoon
Onbekend

Onderwerpen

$6.29
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
Learn2Progress Learn2Progress
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
75
Lid sinds
3 jaar
Aantal volgers
63
Documenten
15
Laatst verkocht
1 jaar geleden

4.6

5 beoordelingen

5
4
4
0
3
1
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen