0% found this document useful (0 votes)
14 views13 pages

Aa1 Answer

Uploaded by

Rafif Irsyadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views13 pages

Aa1 Answer

Uploaded by

Rafif Irsyadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

INTEGRITY DECLARATION FORM

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 :

NAME :MUHAMMAD RAFIF IRSYADI BIN SHAMSUL


ANUAR

MATRIC NO : 82747

COURSE : OBJECT ORIENTED PROGRAMMING k

COURSE INSTRUCTOR : TS SHAMSIAH SUHAILI

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

//Name: Muhammad Rafif Irsyadi bin Shamsul Anuar

//Purpose: Find possible meeting times for a group of Three people

//Date: 16th December 2023

//Author: Muhammad Rafif Irsyadi bin Shamsul Anuar

#include <iostream>

#include <algorithm>

using namespace std;

int main() {

int a[4], b[4], t;

for (int i = 0; i < 3; ++i) {

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

if (t == 1) cout << "8:00-12:00 for morning meet\n";

else if (t == 2) cout << "12:00-18:00 for afternoon meet\n";

else if (t == 3) cout << "18:00-23:00 for night meet\n";

else {

cout << "Wrong number entered\n";

return 1;

3
cout << "Enter hour and minutes of start timing (e.g., 10 30):\n";

cin >> a[i] >> b[i];

int x = min(a[0], a[1]);

int y = min(x, a[2]);

cout << "Person 1, 2, and 3 can meet at ";

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

else cout << "cannot meet\n";

int confirm;

cout << "Press 1 to confirm, 0 for any other time slot:\n";

cin >> confirm;

int z = *min_element(a, a + 3);

cout << "Person 1, 2, and 3 ";

if (confirm == 0) cout << "can meet at ";

else cout << "will meet at ";

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

else cout << "cannot meet\n";

4
return 0;

Explanation about this input:

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.

2. Time Slot Determination (First Two Persons):

- 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.

3. Input Gathering (Third Person):

- Similar to the first two persons, the program collects input for the meeting timings of the third
person.

4. Time Slot Determination (All Three Persons):

- 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.

5. Confirmation or Alternative Time Slot:

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

using namespace std;

double getPricePerOne(char packageCode, char pricePerPerson) {

switch (packageCode) {

case 'A':

return (pricePerPerson == 'X') ? 5490.0 : (pricePerPerson == 'Y') ? 5790.0 : 6090.0 ;

case 'B':

return (pricePerPerson == 'X') ? 6390.0 : (pricePerPerson == 'Y') ? 6690.0 : 6990.0 ;

case 'C':

return (pricePerPerson == 'X') ? 9890.0 : (pricePerPerson == 'Y') ? 10390.0 : 10890.0 ;

default:

return 1.0;

int main() {

double totalPrice = 0;

int countA = 0, countB = 0, countC = 0;

while (true) {

char packageCode, pricePerPerson;

int numberOfPerson = 1;

cout << "\nEnter Package Code (A-Normal, B-School Holiday, C-Ramadhan, X-Exit): ";

cin >> packageCode;

7
if (!(packageCode == 'A' || packageCode == 'B' || packageCode == 'C' || packageCode ==
'X')) {

cout << "Invalid Code\n";

continue;

if (packageCode == 'X')

break;

cout << "\nEnter Price Per Person (X-6, Y-3, Z-2): ";

cin >> pricePerPerson;

if (!(pricePerPerson == 'X' || pricePerPerson == 'Y' || pricePerPerson == 'Z')) {

cout << "Invalid Code\n";

continue;

cout << "\nEnter Number of Persons: ";

cin >> numberOfPerson;

double pricePerOne = getPricePerOne(packageCode, pricePerPerson);

cout << "\nPrice Per Person: " << pricePerOne << endl;

cout << "\nTotal Price for Ticket: " << numberOfPerson * pricePerOne << endl;

totalPrice += numberOfPerson * pricePerOne;

8
switch (packageCode) {

case 'A': countA += numberOfPerson; break;

case 'B': countB += numberOfPerson; break;

case 'C': countC += numberOfPerson; break;

cout << "\nTotal Number of Packages:\nA = " << countA << "\nB = " << countB << "\nC = " <<
countC << endl;

cout << "Total Price of Tickets Sold: " << totalPrice;

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.

8. Nested Switch Statements: There are nested switch statements to handle


different scenarios based on the selected package and price per person code.

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

You might also like