Aa1 Answer
Aa1 Answer
THIS FORM MUST BE COMPLETED AND ATTACHED TOGETHER WITH YOUR COMPLETED ASSIGNMENT /
ALTERNATIVE ASSESSMENT / TAKE HOME TEST&EXAM.
ONLY SUBMISSIONS WITH THIS FORM WILL BE ACCEPTED FOR MARKING.
I HEREBY DECLARE THAT ALL WORKS PRESENTED IN THIS ASSESSMENT ARE FULLY MY OWN ORIGINAL
WORKS.
WHILE I MAY HAVE REFERENCED THE MATERIALS FROM OTHER SOURCES (PRINTED MATERIALS OR THE
INTERNET), ALL PARTS OF WORKS IN THIS ASSESSMENT COMPOSED CAME FROM MY OWN IDEA, CREATIVITY
AND INTERPRETATIONS OF THE SOURCES.
I WITH FREE CONSENT VERIFIED THAT I DO NOT COPIED FROM OTHER PEOPLE, AND HAVE NOT LET MYSELF BE
COPIED BY OTHER PEOPLE.
I UNDERSTAND THAT ANY SIMILARITIES TO WORKS FROM OTHER PEOPLE AND FROM OTHER REFERENCE
MATERIALS INCLUDING THE INTERNET WILL SIGNIFICANTLY REDUCE MARKS FOR THIS ASSESSMENT OR IN
MORE SEVERE CASE, I MAY FAIL THIS ASSESSMENT IF THE SIMILARITIES ARE HIGH.
IN THE EVENT THAT THERE ARE FAILURE, NEGLIGENCE, NON COMPLIANCE , WRONGDOING OR INFORMATION
GIVEN ARE FRAUD, I AGREE AND COMMIT TO WHAT EVER REASONABLE ACTION THAT SHALL BE TAKEN AGAINST
ME.
SIGNED BY :
MATRIC NO : 82747
ASSIGNMENT /:
ALTERNATIVE ASSESSMENT /
TAKE HOME EXAM (MODULE
NAME). :KNR 1743
Object Oriented Programming
Alternative Assessment 1
DATE: 19 December
FACULTY OF ENGINEERING UNIMAS
01.05.2020
QUESTION 1
#include <iostream>
#include <algorithm>
int main() {
cout << "Enter 1 for morning, 2 for afternoon, 3 for night for person " << i + 1 << "
timings:\n";
cin >> t;
cout << "Enter the " << i + 1 << " person timings from ";
else {
return 1;
3
cout << "Enter hour and minutes of start timing (e.g., 10 30):\n";
if (y >= 8 && y < 12) cout << "morning 8:00 am to 12:00 pm\n";
else if (y >= 12 && y < 18) cout << "afternoon 12:00 pm to 6:00 pm\n";
else if (y >= 18 && y <= 23) cout << "night 6:00 pm to 11:00 pm\n";
int confirm;
if (z >= 8 && z < 12) cout << "morning 8:00 am to 12:00 pm\n";
else if (z >= 12 && z < 18) cout << "afternoon 12:00 pm to 6:00 pm\n";
else if (z >= 18 && z <= 23) cout << "night 6:00 pm to 11:00 pm\n";
4
return 0;
1. Input Gathering:
- The program uses a loop to get input for the first two persons' meeting timings, including
morning, afternoon, or night.
- It utilizes a switch statement to handle different cases (1 for morning, 2 for afternoon, 3 for
night) and prompts the user to input start timings.
- After gathering input for the first two persons, the program calculates the earliest common
time slot based on their preferences.
- The result is displayed, indicating whether they can meet in the morning, afternoon, or night.
- Similar to the first two persons, the program collects input for the meeting timings of the third
person.
- The program calculates the earliest common time slot considering the timings of the third
person and the previously determined time slot for the first two persons.
- It displays the result, indicating the potential meeting time for all three persons.
- The user is prompted to confirm the proposed meeting time by entering 1 or choose another
5
time slot by entering 0.
- If the user chooses another time slot, the program sorts the timings and suggests a new
possible meeting time.
6. Final Output:
- Depending on the user's confirmation or choice of an alternative time slot, the program
displays the final meeting time for all three persons.
6
Question 2
#include<iostream>
switch (packageCode) {
case 'A':
case 'B':
case 'C':
default:
return 1.0;
int main() {
double totalPrice = 0;
while (true) {
int numberOfPerson = 1;
cout << "\nEnter Package Code (A-Normal, B-School Holiday, C-Ramadhan, X-Exit): ";
7
if (!(packageCode == 'A' || packageCode == 'B' || packageCode == 'C' || packageCode ==
'X')) {
continue;
if (packageCode == 'X')
break;
cout << "\nEnter Price Per Person (X-6, Y-3, Z-2): ";
continue;
cout << "\nPrice Per Person: " << pricePerOne << endl;
cout << "\nTotal Price for Ticket: " << numberOfPerson * pricePerOne << endl;
8
switch (packageCode) {
cout << "\nTotal Number of Packages:\nA = " << countA << "\nB = " << countB << "\nC = " <<
countC << endl;
return 0;
Explanation:
1. Package Codes: The program uses package codes ‘A,’ ‘B,’ and ‘C’ to represent
different types of packages, and ‘X’ to exit the loop.
2. Price Per Person: It prompts the user to enter the price per person based on
room occupancy (‘X’ for 6 persons, ‘Y’ for 3 persons, and ‘Z’ for 2 persons).
3. Loop Structure: The program uses a while loop that continues until the user
enters ‘X’ for exit.
4. Switch Statements: Switch statements are used to determine the price per one
person based on the chosen package and price per person code.
5. Accumulation: The program accumulates the count of persons for each package
type (countA, countB, countC) and calculates the total price.
6. Output: It outputs the price per person and the total price for each ticket, as
well as the total number of packages and the overall price of tickets sold.
7. Total Price Calculation: The variable totalPrice accumulates the total cost of all
tickets sold, considering the number of persons and the price per one person.
9
9. Input Validation: The code includes input validation to ensure that the entered
package codes and price per person codes are valid. If an invalid code is entered, it informs the
user and continues the loop without processing the input.
10. User Interaction: The program provides clear prompts to the user, guiding them
to enter the package code, price per person code, and the number of persons.
11. Modular Pricing: The pricing logic is modular, allowing for easy modification of
package prices without altering the main structure of the code.
12. Clean Output: The output includes informative messages, such as the price per
person and the total price for each ticket, making it easier for users to understand the
calculations.
Output:
Output 1 shows when I choose a normal package as an A,6 persons/room as X and 4 persons.
The total price is shows which is 21960.
This output shows I choose package B which is School Holiday. After that I key in Y as 3
10
persons/room and I key in 3 as number of persons. The total price of ticket is pop out which is
20070.
As this output, I choose C which is Ramadan.I key in z as I want book for 2 person/ room. I also
key in 1 as number of persons. The total price pop out which is 10890.
This is the total of the packages that have been booked after the user key in X as exit.
11
12
This is the proof that the output are repeating until we key in X as an exit.
13