You are on page 1of 3

NAMA : IRFA IRSYA BINTI SUHAIZAN

NO MATRIC : BI22160523

ANSWER LAB 3
___________________________________________________________________________________
________

PRACTICE 1 :

#include <iostream>
using namespace std;

int main()
{
string n1, n2, n3;
cout << " Please enter three strings in lowercase: ";
cin >> n1 >> n2 >> n3;
cout << " Lexicographical order: ";
if (n1 < n2 && n1 < n3) {
cout << n1;
if (n2 < n3)
cout << n2 << n3;
else
cout << n3 << n2;
}
else if (n2 < n1 && n2 < n3) {
cout << n2;
if (n1 < n3)
cout << n1 << n3;
else
cout << n3 << n1;
}
else if (n3 < n2 && n3 < n1) {
cout << n3;
if (n2 < n1)
cout << n2 << n1;
else
cout << n1 << n2;
}

return 0;
}

PRACTICE 2 :

#include <iostream>
using namespace std;

int main()
{
char c;
bool isLowercaseVowel, isUppercaseVowel;

cout << "Enter an a single letter: ";


cin >> c;

// evaluates to 1 (true) if c is a lowercase vowel


isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

// evaluates to 1 (true) if c is an uppercase vowel


isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

// show error message if c is not an alphabet


if (!isalpha(c))
printf("Error! Non-alphabetic character.");
else if (isLowercaseVowel || isUppercaseVowel)
cout << c << " is a vowel.";
else
cout << c << " is a consonant.";

return 0;
}

PRACTICE 3 :

#include <iostream>
#include <iomanip>
// std :: setprecision()
using namespace std;

int main()
{
char car_type;
int hour_in, minute_in, hour_left, minute_left, tot_hour, tot_min, charges{},
penalty{};

cout << "Type of vehicle? : ";


cin >> car_type;
cout << "\nHour vehicle entered lot (0 - 24) ? : ";
cin >> hour_in;
cout << "Minute vehicle entered lot (0 - 60) ? : ";
cin >> minute_in;
cout << "\nHour vehicle left lot (0 - 24) ? : ";
cin >> hour_left;
cout << "Minute vehicle left lot (0 - 60) ? : ";
cin >> minute_left;

cout << "\n\t\t\tBorneo Parking Sdn. Bhd.";


cout << "\n\t\t\tPARKING LOT CHARGE";

cout << "\nTYPE OF VEHICLE : ";


if (car_type == 'c' || car_type == 'C') {
cout << "CAR";
}
else if (car_type == 'b' || car_type == 'B') {
cout << "BUS";
}
else if (car_type == 'm' || car_type == 'M') {
cout << "MPV";
}
cout << "\nTIME - IN\t " << hour_in << " : " << minute_in;
cout << "\nTIME - OUT\t " << hour_left << " : " << minute_left;
cout << "\n\t\t----------";

if (hour_in > hour_left) {


tot_hour = hour_in - hour_left;
}
else {
tot_hour = hour_left - hour_in;
}
if (minute_in > minute_left) {
tot_min = minute_in - minute_left;
}
else {
tot_min = minute_left - minute_in;
}
cout << "\nPARKING TIME\t " << (tot_hour) << " : " << (tot_min);
cout << "\n\t\t----------";

if (car_type == 'c' || car_type == 'C') {


charges = (2 * 2) + ((tot_hour - 2) * 3);
}
else if (car_type == 'b' || car_type == 'B') {
charges = (2 * 4) + ((tot_hour - 2) * 5);
}
else if (car_type == 'm' || car_type == 'M') {
charges = (2 * 3) + ((tot_hour - 2) * 4);
}
cout << "\nPARKING FARE\t RM " << fixed << setprecision(2) << (float)
(charges);

//Penalty
if (hour_in > hour_left) {
penalty = 100;

}
else if (tot_hour < 24) {
penalty = 0;
}

//Price Output total charge


cout << "\nPENALTY FARE\t RM " << fixed << setprecision(2) << (float)
(penalty);

cout << "\n\t\t----------";


cout << "\nTOTAL CHARGE\t RM " << fixed << setprecision(2) << (float)(charges
+ penalty);
cout << "\n\t\t----------";

You might also like