COS1512 2023 ASSIGNMENT 2
DISCUSSION
(with the source code you need)
Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187
***copy and run the code, then submit what you need to submit***
Or ask for the source code
if there is a program that is not running, please contact
,Question 1
#include <iostream>
using namespace std;
// Function to calculate tuition fees for a student without repeated modules
double calcFees(int numModules, double moduleFee)
{
return numModules * moduleFee;
}
// Function to calculate tuition fees for a student with repeated modules
double calcFees(int numModules, double moduleFee, int numRepeatedModules,
double repeatedModuleFee)
{
return (numModules * moduleFee) + (numRepeatedModules * repeatedModuleFee);
}
int main()
{
int numModules, numRepeatedModules;
double moduleFee, repeatedModuleFee;
cout << "Does the student repeat any modules? (1 for Yes, 0 for No): ";
int repeatModules;
cin >> repeatModules;
cout << "Enter the number of modules enrolled for the first time: ";
cin >> numModules;
cout << "Enter the fee for those modules: R";
cin >> moduleFee;
if (repeatModules)
{
cout << "Enter the number of modules repeated: ";
cin >> numRepeatedModules;
cout << "Enter the fee for the repeated modules: R";
cin >> repeatedModuleFee;
double totalFees = calcFees(numModules, moduleFee, numRepeatedModules,
repeatedModuleFee);
cout << "Total tuition fees: R" << totalFees << endl;
}
else
{
double totalFees = calcFees(numModules, moduleFee);
cout << "Total tuition fees: R" << totalFees << endl;
}
return 0;
}
, Output
Question 2
#include <iostream>
#include <cassert>
using namespace std;
void convertTo12Hour(int hour24, int minute)
{
assert(hour24 >= 0 && hour24 < 24 && minute >= 0 && minute < 60);
string meridiem = (hour24 < 12) ? "AM" : "PM";
int hour12 = (hour24 == 0 || hour24 == 12) ? 12 : hour24 % 12;
cout << "12-hour notation: " << hour12 << ":" << minute << " " << meridiem
<< std::endl;
}
int main()
{
int hour24, minute;
cout << "Enter time in 24-hour notation (hour minute): ";
cin >> hour24 >> minute;
convertTo12Hour(hour24, minute);
return 0;
}
DISCUSSION
(with the source code you need)
Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187
***copy and run the code, then submit what you need to submit***
Or ask for the source code
if there is a program that is not running, please contact
,Question 1
#include <iostream>
using namespace std;
// Function to calculate tuition fees for a student without repeated modules
double calcFees(int numModules, double moduleFee)
{
return numModules * moduleFee;
}
// Function to calculate tuition fees for a student with repeated modules
double calcFees(int numModules, double moduleFee, int numRepeatedModules,
double repeatedModuleFee)
{
return (numModules * moduleFee) + (numRepeatedModules * repeatedModuleFee);
}
int main()
{
int numModules, numRepeatedModules;
double moduleFee, repeatedModuleFee;
cout << "Does the student repeat any modules? (1 for Yes, 0 for No): ";
int repeatModules;
cin >> repeatModules;
cout << "Enter the number of modules enrolled for the first time: ";
cin >> numModules;
cout << "Enter the fee for those modules: R";
cin >> moduleFee;
if (repeatModules)
{
cout << "Enter the number of modules repeated: ";
cin >> numRepeatedModules;
cout << "Enter the fee for the repeated modules: R";
cin >> repeatedModuleFee;
double totalFees = calcFees(numModules, moduleFee, numRepeatedModules,
repeatedModuleFee);
cout << "Total tuition fees: R" << totalFees << endl;
}
else
{
double totalFees = calcFees(numModules, moduleFee);
cout << "Total tuition fees: R" << totalFees << endl;
}
return 0;
}
, Output
Question 2
#include <iostream>
#include <cassert>
using namespace std;
void convertTo12Hour(int hour24, int minute)
{
assert(hour24 >= 0 && hour24 < 24 && minute >= 0 && minute < 60);
string meridiem = (hour24 < 12) ? "AM" : "PM";
int hour12 = (hour24 == 0 || hour24 == 12) ? 12 : hour24 % 12;
cout << "12-hour notation: " << hour12 << ":" << minute << " " << meridiem
<< std::endl;
}
int main()
{
int hour24, minute;
cout << "Enter time in 24-hour notation (hour minute): ";
cin >> hour24 >> minute;
convertTo12Hour(hour24, minute);
return 0;
}