You are on page 1of 11

CS404

PROGRAMMING 2
ASSIGNMENT 1

PREPARED BY: SYAFIQAH BATRISYIA BINTI MOHD ZAHIR


LECTURER: ROS SYAMIMI BINTI HAMID
MATRIC NO: 2022821848
GROUP: RCS2552A
TASK 1

Algorithm:

/*

Name : Syafiqah Batrisyia Binti Mohd Zahir

Sid# : 2022821848

Course : CSC404

Group# : RCSCS2552A

Assign# : 24 April 2023

Due Date: 3rd May 2023 (12 midnight)

Program Description: Task 1

*/

#include <iostream>

#include <cmath>

using namespace std;

float triangle (float, float);

float square (float, float);

float triangle (float x, float y)

double areaT = 0.5 * (x * y);

return areaT;

float square (float x, float y)

double areaS = x * y;

return areaS;

}
int main()

float x, y;

int shape;

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

cout<< "1. Tringle\n2. Square"<< endl;

cin>> shape;

cout<< "What is the length of the shape : "<< endl;

cin>> x;

cout<< "What is the width of the shape : "<< endl;

cin>> y;

if(shape = 1 && shape != 2)

double areaT = triangle(x,y);

cout<< "The area for triangle is : "<< triangle(x,y)<< endl;

else if(shape = 2 && shape != 1)

double areaS = square(x,y);

cout<< "The area for square is : "<< square(x,y)<< endl;

return 0;

}
C++ Program:
Output:

Sample 1

Sample 2
TASK 2

Algorithm:

/*

Name : Syafiqah Batrisyia Binti Mohd Zahir

Sid# : 2022821848

Course : CSC404

Group# : RCSCS2552A

Assign# : 25 April 2023

Due Date: 3rd May 2023 (12 midnight)

Program Description: Task 2

*/

#include<iostream>

using namespace std;

void DisplayPackage();

float CalcPrice(int ,int , int);

void DisplayPackage()

cout<<"--------------------------------------"<<endl;

cout<<"| Package Type | Traveler | Price |"<<endl;

cout<<"|------------------------------------|"<<endl;

cout<<"| Premium | Kid | RM 59.60 |"<<endl;

cout<<"| ----------------------|"<<endl;

cout<<"| | Adult | RM 78.60 |"<<endl;

cout<<"|------------------------------------|"<<endl;

cout<<"| Economic | Kid | RM 48.30 |"<<endl;

cout<<"| ----------------------|"<<endl;

cout<<"| | Adult | RM 62.50 |"<<endl;

cout<<"|------------------------------------|"<<endl;

cout<<"| Budget | Kid | RM 39.00 |"<<endl;


cout<<"| ----------------------|"<<endl;

cout<<"| | Adult | RM 55.00 |"<<endl;

cout<<"--------------------------------------"<<endl;

float CalcPrice(int package,int k, int a)

float tpriceKid,tpriceAdult,tprice;

if(package == 1)

tpriceKid = k * 59.60 ;

tpriceAdult = a * 78.60 ;

tprice = tpriceKid + tpriceAdult;

if(k + a > 5)

tprice = tprice * 0.95 ;

else

tprice;

else if(package == 2)

tpriceKid = k * 48.30 ;

tpriceAdult = a * 62.50 ;

tprice = tpriceKid + tpriceAdult ;

if(k + a > 5)

tprice = tprice * 0.95 ;


}

else

tprice;

else if(package == 3)

tpriceKid = k * 39.00 ;

tpriceAdult = a * 55.00 ;

tprice = tpriceKid + tpriceAdult ;

if(k + a > 5)

tprice = tprice * 0.95 ;

else

tprice;

int main()

int packageType , k , a;

cout<<"Welcome!"<<endl;

cout<<"These are the details of package offered by Syarikat Percutian Era Sdn Bhd"<<endl;

DisplayPackage();

cout<<"You can choose what package type that do you want ?"<<endl;

cout<<"1. Premium\n2. Economic\n3. Budget"<<endl;

cin>>packageType;

cout<<endl;
cout<<"With same package, how many kid and adult in your group ?"<<endl;

cout<<"Kid : ";

cin>>k;

cout<<"Adult : ";

cin>>a;

float totprice = CalcPrice(packageType, k, a);

cout<<endl;

cout<<"Your total price is : " << totprice << endl;

C++ Program:
Output:

Sample 1

More than 5 travellers

Sample 2

Less than 5 travellers

You might also like