COS 1512 ASSIGNMENT 1
Question 1 INPUT: #include iostream using namespace std; void calcCharges(int daysInHospital, double dayRate, double mediCharges, double serviceCharges) { double totalCharges; totalCharges = ((daysInHospital * dayRate) + mediCharges + serviceCharges); (ios::fixed); (ios::showpoint); sion(2); cout "The Total Charges for hospital stay is: R" totalCharges; } int main() { int daysInHospital; double dayRate, mediCharges, serviceCharges; char patientType; cout "*** CHARGES FOR PATIENT HOSPITAL STAY ***" endl endl; cout "Was the patient admitted as an in-patient? (y or n)" endl; cin patientType; if (patientType == 'y' || patientType == 'Y') { cout "Number of days spent in hospital: "; cin daysInHospital; cout "Daily Rate: R"; cin dayRate; cout "Hospital Medication Charges: R"; cin mediCharges; cout "Charges for hospital services: R"; cin serviceCharges; calcCharges(daysInHospital, dayRate, mediCharges, serviceCharges); } else { cout "Hospital Medication Charges: R"; cin mediCharges; cout "Charges for hospital services: R"; cin serviceCharges; calcCharges(daysInHospital == 0, dayRate == 0, mediCharges, serviceCharges); } cout endl; return 0; } OUTPUT: *** CHARGES FOR PATIENT HOSPITAL STAY *** Was the patient admitted as an in-patient? (y or n) y Number of days spent in hospital: 3 Daily Rate: R200 Hospital Medication Charges: R100 Charges for hospital services: R100 The Total Charges for hospital stay is: R800.00 RUN FINISHED; exit value 0; real time: 1m 1s; user: 0ms; system: 0ms *** CHARGES FOR PATIENT HOSPITAL STAY *** Was the patient admitted as an in-patient? (y or n) n Hospital Medication Charges: R100 Charges for hospital services: R100 The Total Charges for hospital stay is: R200.00 RUN FINISHED; exit value 0; real time: 5s; user: 0ms; system: 0ms QUESTION 2 INPUT: #include iostream #include cassert using namespace std; int main () { int maths, phySci, eng; cout "*** CHECK IF YOU QUALIFY FOR BSC COMPUTER SCIENCE DEGREE ***" endl; cout endl "Mathematics Mark: "; cin maths; cout "Physical Science Mark: "; cin phySci; cout "English Mark: "; cin eng; assert((maths 100) && (phySci 100) && (eng 100)); if ((maths = 60) && (phySci = 60) && (eng = 60)) { cout endl "You qualify for the BSC Computer Science degree." endl; } else { cout "You do not qualify for the BSC Computer Science degree." endl; } cout endl;
Geschreven voor
- Instelling
- University of South Africa
- Vak
- COS 1512
Documentinformatie
- Geüpload op
- 16 september 2021
- Aantal pagina's
- 11
- Geschreven in
- 2021/2022
- Type
- Tentamen (uitwerkingen)
- Bevat
- Vragen en antwoorden
Onderwerpen
-
cos
-
1512
-
ass1