0% found this document useful (0 votes)
29 views

Lab Assignment Programming

The document appears to be a lab assignment for a programming course. It includes code for calculating the area of basic shapes like triangles and squares, as well as code for calculating travel package prices based on user input for the number of adults and children. There is also code provided to calculate averages and find the maximum score from an array of scores to determine the champion in an e-games competition between groups.

Uploaded by

elissaysmn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Lab Assignment Programming

The document appears to be a lab assignment for a programming course. It includes code for calculating the area of basic shapes like triangles and squares, as well as code for calculating travel package prices based on user input for the number of adults and children. There is also code provided to calculate averages and find the maximum score from an array of scores to determine the champion in an e-games competition between groups.

Uploaded by

elissaysmn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

FACULTY OF COMPUTER AND MATHEMATICAL SCIENCE

BACHELOR IN COMPUTER SCIENCE (HONOURS) NETWORKING

CSC 404
LAB ASSIGNMENT 1
PROGRAMMING II

LECTURER: MADAM SHAKIRAH BINTI KIYO

NAME:
STUDENT ID:
LAB ASSIGNMENT PROGRAMMING

#include <iostream>

using namespace std;

float triangle(float length, float width) {

float area = 0.5 * length * width;

return area;

float square(float length, float width) {

float area = length * width;

return area;

int main() {

float length, width;

int shape;

cout << "Choose the shape: " << endl;

cout << "1. Triangle" << endl ;

cout << "2. Square" << endl ;


cin >> shape;

// User Input

cout << "Enter the length: ";

cin >> length;

cout << "Enter the width: ";

cin >> width;

if(shape == 1){

// Calculate and display the area of the triangle

float triangle_area = triangle(length, width);

cout << "Area of the triangle: " << triangle_area << endl;

else if(shape ==2){

// Calculate and display the area of the square

float square_area = square(length, width);

cout << "Area of the square: " << square_area << endl;

else

cout << "Invalid input. PLease enter 1 or 2";

return 0;

}
Name: Elissa Yasmeen Binti Muhamad Yusni

Sid#: 2022455318

Course: CSC404

Group#: CS2552B

Assign#:

Due Date: 25 May 2023 (12 Midnight)

Program Description:

#include <iostream>

#include <iomanip>

using namespace std;

void DisplayPackage();

float calcPrice(int packageNum, int adultNum, int childNum);

// Price for all Package

#define premiumAdult 78.60

#define premiumChild 59.60

#define ecoAdult 62.50

#define ecoChild 48.30

#define budgetAdult 55.00

#define budgetChild 39.00


int main(){

int packageNum;

int adultNum, childNum;

float totalPrice;

DisplayPackage();

cout << "Please choose a package: \n[1] Premium\n[2] Economy\n[3] Budget\n";

cin >> packageNum;

cout << "Enter number of adult: ";

cin >> adultNum;

cout << "Enter number of children: ";

cin >> childNum;

totalPrice = calcPrice(packageNum, adultNum, childNum);

cout << "Your total price is RM" << totalPrice;

void DisplayPackage(){

cout << fixed << setprecision(2);

cout << "Package Details offered by Syarikat Percutian Era Sdn Bhd:" << endl;

cout << "Package Type\t\tTraveler\tPrice" << endl;

cout << "Premium\t\t\tKid\t\t" << premiumChild << endl;

cout << "\t\t\tAdult\t\t" << premiumAdult << endl;

cout << "Economic\t\tKid\t\t" << ecoChild << endl;

cout << "\t\t\tAdult\t\t" << ecoAdult << endl;

cout << "Budget\t\t\tKid\t\t" << budgetChild << endl;

cout << "\t\t\tAdult\t\t" << budgetAdult << endl;

float calcPrice(int packageNum, int adultNum, int childNum){


float pricePerChild, pricePerAdult, totalPrice;

switch (packageNum){

case 1:

pricePerChild = premiumChild;

pricePerAdult = premiumAdult;

break;

case 2:

pricePerChild = ecoChild;

pricePerAdult = ecoAdult;

break;

case 3:

pricePerChild = budgetChild;

pricePerAdult = budgetAdult;

break;

default:

cout << "Invalid package input";

return 0;

totalPrice = (pricePerChild * childNum) + (pricePerAdult * adultNum);

if ((adultNum + childNum) > 5)

totalPrice = totalPrice * 0.95;

return totalPrice;

}
#include <iostream>

using namespace std;

int maxRound(float score[]) {

int bestRound = 0;

float maxScore = score[0];

for (int i = 1; i < 4; i++) {

if (score[i] > maxScore) {

maxScore = score[i];

bestRound = i;

return bestRound;

float average(float score[], char group) {

float sum = 0;

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

sum += score[i];

float avg = sum / 4;


cout << "The average for Group " << group << " is " << avg << endl;

return avg;

void find_champ(float avgA, float avgB, float avgC) {

if (avgA > avgB && avgA > avgC) {

cout << "Group A is the champion of the E-Games competition." << endl;

} else if (avgB > avgA && avgB > avgC) {

cout << "Group B is the champion of the E-Games competition." << endl;

} else if (avgC > avgA && avgC > avgB) {

cout << "Group C is the champion of the E-Games competition." << endl;

} else {

cout << "There is a tie for the champion of the E-Games competition." << endl;

int main() {

float scoreA[] = {57.2, 54.4, 32.6, 28.6};

float scoreB[] = {19.5, 33.3, 86.2, 28.3};

float scoreC[] = {58.5, 39.2, 42.5, 93.1};

cout << "Group A scores: ";

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

cout << scoreA[i] << " ";

cout << endl;

cout << "Group B scores: ";

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

cout << scoreB[i] << " ";

cout << endl;


cout << "Group C scores: ";

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

cout << scoreC[i] << " ";

cout << endl;

int bestRoundA = maxRound(scoreA);

int bestRoundB = maxRound(scoreB);

int bestRoundC = maxRound(scoreC);

cout << "Best round for Group A: " << bestRoundA + 1 << endl;

cout << "Best round for Group B: " << bestRoundB + 1 << endl;

cout << "Best round for Group C: " << bestRoundC + 1 << endl;

float avgA, avgB, avgC;

avgA = average(scoreA, 'A');

avgB = average(scoreB, 'B');

avgC = average(scoreC, 'C');

find_champ(avgA, avgB, avgC);

return 0;

You might also like