# data[].attributes.attachment_link.readable_text
// parking system :
// operating time 10.00 - 22.00 every day.
// the first two hours everycar will be charge RM 2.00.
// the next hour will be charged RM 1.00 .
// there are 100 parking spaces available.
// if the parking spaces are full, then the customer's car is not allow to enter the parking area.


// at the end of the operation the system has ability:
// to calculate the amount of RM got on that day.
// total number of cars parked at the parking area.


#include <iostream> 
#include <string>
using namespace std;


struct waktu
{
	 int jam; // hour 0..23
	 int minit; // minute 0..59
	 int saat; // second 0..59
	 

};

struct kereta
{
	string platenumber;
	waktu masuk;
	waktu keluar;
	
};

int const SIZE = 100;
kereta parks[SIZE];
int total_number_of_parked_kereta;


void set_waktu(waktu &w);
void show_wakttu(waktu w);
//waktu subtract_waktu(waktu masuk,waktu keluar);

void set_kereta_masuk (kereta &k);
void set_kereta_keluar (kereta &k);

bool search_kereta(int &indexWanted); // find the car and return true if found
int get_integer_number;

int main()
{

	char(pilihan);
	waktu masuk , waktu keluar;
	kereta thekereta;
	int total_number_of_kereta = 0;
	int total_number_of_cars = 0;
	int indexWanted;


	cout << ("**********WELCOME TO CAR PARKING ZONE**********") << endl;
	cout << "\t 1. Kereta Masuk" << endl;
	cout << "\t 2. Kereta Keluar" << endl;
	cout << "\t 3. Exit" << endl;
	
	
	cout << "\t Enter your choice" << endl;
	cin >> pilihan;

	switch (pilihan)
	
	{
	case '1' :
		cout << "\t Kereta Masuk " << endl;
		if (total_number_of_parked_kereta < SIZE) // not full
			
		{
			set_kereta_masuk (thekereta);
			show_wakttu(thekereta.masuk);
			parks(total_number_of_parked_kereta);
			total_number_of_parked_kereta++;
			total_number_of_cars++;
		}

		else // FULL
			cout << "\n\t FULL..!" << endl << endl;

			cout << "\n\t Total number of parked kereta = " << total_number_of_parked_kereta << endl;
				
			cout << "\n\t Total number of cars = " << total_number_of_cars << endl;
				break;


	case '2' :
		cout << "\t 2. Kereta Keluar " << endl;
				cout << "\n\t Enter plate number: ";
			
				if (search_kereta(int &indexWanted)
				{
					total_number_of_parked_kereta--;
				}
				cout << "\n\t Total number of parked kereta = " << total_number_of_parked_kereta << endl;
				cout << "\n\t Total number of cars = " << total_number_of_cars << endl;
				break;

	case '3' :
		cout << "\t Exit " << endl;
	break;

	default:
		cout << "\n\t Enter either 1, 2, or 3 ONLY ... " << endl;
		
		}

		while (pilihan != '3');

	
return 0;

}

void set_kereta_masuk (kereta &k)

{

cout << "Enter Your Plate Number"<< endl;
cin >> k.platenumber;

cout << "\n\t Enter entry time :"<< endl;
set_waktu(k.masuk);

}

void set_kereta_keluar (kereta &k)
{
	int indexWanted = 0;
	
	if(search_kereta(indexWanted))
	{
		k = parks[indexWanted];
		cout << "\n\t Enter exit time: " << endl;
		set_waktu(k.keluar);
	}
		
}
bool search_kereta(int &indexWanted)
{
	bool found = true;
	string platenumber;
	cout<< "\n\t Enter plate number :" ;
	for (int index = 0; < total_number_of_parked_kereta; index++)

	{
		if (parks [index].platenumber == platenumber)
		{
			indexWanted = index;
			break;
		}
	}

}
	return number;



	void show_waktu(waktu &w)
{
	cout << "\n\t " << w.jam << ":" << w.masa << ":" << w.saat << endl << endl;
}
int get_integer_number()
{
	int number = 0;
	while(!(cin >> number ))
	{
		cin.clear();
		cin.ignore();
	}
	return number;
}

void set_waktu (waktu &w)
{
	int h = 0 ,m = 0 ,s = 0;

	do 
	{
	
		cout << "enter jam ";
		cin >> h;
	}
	while (h>0 || h<23);
	do
	{
		cout << "enter minute";
		cin >> m;
		
	} while (m<0 || m>59 );
	do
	{
		cout << "enter saat";
		cin >> s;

	} while (s<0 || s> 59);

		w.jam = h;
		w.minit= m;
		w.saat = s;

}

int main()
{
	
	float floatHour = 2;
	float floatFees = 2.00;
	cout << "Enter number of hours parked: ";
	cin >> floatHour;
	if (floatHour > 2)
	{
		floatFees += (int)(floatHour-2.00)*1.00;
		if( floatHour/(int)floatHour > 1 )
			floatFees += 1.00;
		if (floatFees > 2)
			floatFees = 2;
	}
	cout << "Your total is: RM" << floatFees << endl;
	return 0;


}

# data[].attributes.attachment_link.readable_text
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	char operation;
	double first_number;
	double second_number;
	double solution = 0;


	do
	{
		cout << "This is a basic calculator program, enter the first number.\n";
		cout << "First number:";
		cin >> first_number;

		cout << "Enter second number:";
		cin >> second_number;

		cout << "\nEnter an operation to perform, choose one from this list: +,-,/,*\n";
		cout << "Enter your operation:";
		cin >> operation;
		cin.ignore();
		cout << endl << endl;
		if ((operation == 'Q') || (operation == 'q'))
		{
			return EXIT_SUCCESS;
		}
	

		if (operation != '+' && operation != '-'&& operation != '/'&& operation != '*')
		{
        cout << "\nInvalid operation! Aborting!";
        cout << "\nPress Enter to exit.";
        cin.get();
		return 1;
		
		}//end if

if (operation == '+')
    {
        solution = first_number + second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();
        return 0;
    }//end if

if (operation == '-')
    {
        solution = first_number - second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();
        return 0;
    }//end if

if (operation == '*')
    {
        solution = first_number * second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();
        return 0;
    }//end if

if (operation == '/')
    {
        if ( second_number == 0 )
        {
            cout << "\nYou can't divide by zero! Aborting!";
            cout << "\nPress Enter to exit.";
            cin.get();
            return 2;
        }//end if
        solution = first_number / second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();

	}
	while((operation!='Q') && (operation!='q'));
	system("PAUSE");
	return EXIT_SUCCESS;

}
	}while((operation!='Q') && (operation!='q'));
	system("PAUSE");
	return EXIT_SUCCESS;

	}while((operation!='Q') && (operation!='q'));
	system("PAUSE");
	return EXIT_SUCCESS;

}

	

# data[].attributes.attachment_link.readable_text

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


int main ()
{

//Input variables
int Minutes, TimeStarted;
char choice;
string Day; 

//Output variables
double cost, rate;

//Format demical place
cout << fixed << showpoint << setprecision (2); 

//Using do while loop to ask the user if he/she wants to calculate his/her bill again
do
{
//Prompt the user to input
cout << "Enter the start time of the call in 24 hour format time " << endl
<< "For example, 1:30 = 1330: ";
cin >> TimeStarted;


//Using while loop that ask the user to enter the starting time again if the user 
//failed in inputting the starting time in the right format.
while(TimeStarted < 0 || TimeStarted >= 2400)
{
cout << "\nYou entered a non valid Time.";
cout << "\nEnter the start time of the call in  24 hour format time " << endl
<< "For example, 1:30 = 1330: ";
cin >> TimeStarted;

}

cout << "Enter the length of the call in minutes: ";
cin >> Minutes;
cout << "Enter the day of the week on which you called using " <<
"only the first two letters of the day. (Monday = mo): ";
cin >> Day;


//Using if statment to determine the right cost of the call on a certain day.
if(Day == "mo"|| Day == "Mo" || Day == "MO" || Day == "tu" || Day == "Tu" || Day =="TU" 
|| Day =="we" || Day == "We" || Day =="WE" || Day =="th" || Day == "Th" || Day =="TH"
|| Day == "fr" || Day =="Fr" || Day == "FR")

{ 


//Using if statment to determine the right cost of the call on a certain time.
if (TimeStarted >= 800 && TimeStarted <= 1800) 
rate = 10.0; 
else 
rate = 0.50;
//Calculation
cost = Minutes * rate;
cout << "\nyour rate for the call was " << "RM" << rate << " a minute"<< endl
<< "Your total cost: " << "RM" << cost << endl;

}
else if(Day =="sa" || Day =="Sa" || Day =="SA" || Day =="su" || Day =="Su" || Day =="SU")
{
rate = 3.00;


//Calculation
cost = Minutes * rate;
cout << "\nyour rate for the call was " << "RM" << rate << " a minute"<< endl
<< "Your total cost: " << "RM" << cost;

}
else
cout <<"You entered a non valid entry. Try again.";

cout << endl << "\nWould you like to calculate your bill again? (y/n): ";
cin >> choice;
cout << endl << endl;

}
while( choice =='Y' || choice == 'y');

//closing
cout << "\nEnd of Program\n\n"; 
return 0;
}

//saya ikut code di internet

# data[].attributes.body
dr, saya punya code nih tak leh run sbb ada error pada curly bracket..saya tak paham kenapa.. mtk tlg dr tgokkn

# data[].attributes.attachment_link.readable_text
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	char operation;
	double first_number;
	double second_number;
	double solution = 0;


	do
	{
		cout << "This is a basic calculator program, enter the first number.\n";
		cout << "First number:";
		cin >> first_number;

		cout << "Enter second number:";
		cin >> second_number;

		cout << "\nEnter an operation to perform, choose one from this list: +,-,/,*\n";
		cout << "Enter your operation:";
		cin >> operation;
		cin.ignore();
		cout << endl << endl;
		if ((operation == 'Q') || (operation == 'q'))
		{
			return EXIT_SUCCESS;
		}
	

		if (operation != '+' && operation != '-'&& operation != '/'&& operation != '*')
		{
        cout << "\nInvalid operation! Aborting!";
        cout << "\nPress Enter to exit.";
        cin.get();
		return 1;
		
		}//end if

if (operation == '+')
    {
        solution = first_number + second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();
        return 0;
    }//end if

if (operation == '-')
    {
        solution = first_number - second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();
        return 0;
    }//end if

if (operation == '*')
    {
        solution = first_number * second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();
        return 0;
    }//end if

if (operation == '/')
    {
        if ( second_number == 0 )
        {
            cout << "\nYou can't divide by zero! Aborting!";
            cout << "\nPress Enter to exit.";
            cin.get();
            return 2;
        }//end if
        solution = first_number / second_number;
        cout << "\nYour answer is: " << solution << "\nPress Enter to exit.\n";
        cin.get();

	}while((operation!='Q') && (operation!='q'));
	system("PAUSE");
	return EXIT_SUCCESS;

}

	ni soalan nya :
/*The calculator program should received two input two integers 
	and the operation to be performed.
	It should then output the numbers, the operator, and the result.
   	Use while loop to repeat the calculation for other inputs
   	until the user choose to stop.*/

# data[].attributes.attachment_link.readable_text
#include <iostream>
using namespace std;

void add (double a, double b, double &c);

int main ()
{
	double x = 10.5 ,y = 20.5,z;

	add (x, y, z);

	cout << z ;
	return 0;
}

void add (double a, double b, double &c)
{
	c= a+b;
}

# data[].attributes.attachment_link.readable_text
//process:
//one output/result:
//additional -> c = a+b
//subtraction -> = a-b
//multiplication -> c = a*b
//divide -> c = a/b , constraint -> b=0

#include <iostream>
using namespace std;

//function declaration
double add (double a, double b);
double substract (double a, double b);
double multiply (double a, double b);
bool divide (double a, double b, double &c);
void setArray(double array[], int size);
void showArray(double array[], int size);
void getAllInfo (double array [], int size,
	double &max, double &min, double &average, double &total);



int main()
{
	/*
	double v = 10, w = 20, x = 30, y = 40, z;

	cout<< "\n\t x + y = " << x << " + " << y << " = " << add(x,y) << endl;
	cout<< "\n\t x - y = " << x << " - " << y << " = " << substract(x,y) << endl;
	cout<< "\n\t x * y = " << x << " * " << y << " = " << multiply(x,y) << endl;


	if (divide(x,y,z))
	{
		cout<< "\n\t x / y = " << x << " / " << y << " = " << z << endl;
	}

	cout << endl << endl;
	cout << "\n\t v, w, x, y = " << v << " " << w << " " << x << " " << y << " " << endl;
	cout << "\n\t total for 4 parameters v, w, x, y: " << endl << endl;
	cout << "\n\t v + w + x + y = " << x << " + " << y << " = " << add(add(add(v,w),x),y) << endl;
	cout << "\n\t v - w - x - y = " << x << " - " << y << " = " << substract(substract(substract(v,w),x),y) << endl;
	cout << "\n\t v * w * x * y = " << x << " * " << y << " = " << multiply(multiply(multiply(v,w),x),y) << endl;
	
	z = add(v,w);
	z = add(z,x);
	z = add(z,y);

	cout << "\n\t v + w + x + y + z = " << endl;

	divide (v, w, z);
	divide (z, x, z);
	divide (z, y, z);
	cout << "\n\t v/w/x/y = " << z << endl;

	*/

	double thearray[10];
	double max, min, total, average;


	setArray(thearray, 10);
    showArray(thearray, 10);



	getAllInfo (thearray, 10, max,min, average, total);
	cout <<"\n\t max = "<< max << endl;
	cout <<"\n\t min = "<< min << endl;
	cout <<"\n\t average = " << average << endl;
	cout <<"\n\t total = " << total << endl;



	return 0;
} //end main

//function definition/body:


void getAllInfo (double array [], int size,
	double &max, double &min, double &average, double &total)
{
	min = array[0];
	max = array[0];
	total = 0.0;

	for (int index =0; index < size; index++)
	{ 
		total = total + array[index];

		//to find min:

			if (array[index] < min)
			{
				min = array[index];
			}

			//to find max:
			if (array[index] > max)
			{
				max = array[index];
			}
		
	}

	average = total /size;

}//end getInfo






void showArray(double array[], int size)
{
	cout <<"\n\t element index: " ; 
	for (int index =0; index < size; index++)
	{ 
		cout <<"\n\t Enter element index " << index << " : ";
		
	}
}


void setArray(double array[], int size)
{
	for (int index = 0; index < size; index++)
	{
		cout <<"\n\t Enter element index " << index << " : ";
		cin >> array[index];
	}

}//end void setArray(int array[], int size);



        double add (double a, double b)
        {
	        double tmp;
			tmp = a + b;
			return tmp;
		}

		double substract (double a, double b)
		{
	        double tmp;
			tmp = a - b;
			return tmp;
		}

		double multiply (double a, double b)
		{
	        double tmp;
			tmp = a * b;
			return tmp;
		}

		bool divide (double a, double b, double &c)
		{
	        bool status = true;
			c = 0.0;
			if (b !=0)
			{
				c= a /b ;
			}
			else
			{
				status = false;
			cout << "\n\t divide by ZERO....!" << endl << endl;
		     }
		return status;

		}

# data[].attributes.body
lab 1 (latihan 1)

# data[].attributes.attachment_link.readable_text
// to initialize array slement
#include <iostream>
using namespace std;

int main()
{
	int myarray[10];
	int item;
	//key in integer data (10x):
	for (int i =0;i<10;i++)
	{
		cout << "\n\t Enter integer data:";
		cin >> item;
		myarray[i]=item;

	};

	cout << "\n\t the data are:";

	for (int i =0;i<10;i++)
	{
		
		cout<<myarray[i]<<"  ";

	}
	cout<<endl;

	return 0;
}	//end of main

# data[].attributes.body
latihan 3

# data[].attributes.attachment_link.readable_text

#include <iostream>
using namespace std;

#include <ctime>
#include <cstdlib>
int* getRandomNumbers (int number);



int main()
{
	int* thearray;
	thearray = getRandomNumbers(10);

	cout<< endl << endl;
	for (int index = 0; index<10; index++)

	{
		cout << thearray[index] << " ";

	}

	cout << endl << endl;
		

	return 0;
}


 int* getRandomNumber (int number)
{

	int* array(number);  // ada error pada "number"
		if (number <= 0)
			return NULL;

		array = new int[number];
		srand ( time (0) );

		 for (int count = 0; count < number; count++)
			 array[count] = rand() % 100 + 1;

		 return array;
}



# data[].attributes.attachment_link.readable_text
#include <iostream>
using namespace std;

void setMatrix(double matrix[][10], int rows, int columns);
void showMatrix(double matrix[][10], int rows, int columns);

int main ()
{
	double matrixA[10][10];
	setMatrix(matrixA,2,2);
	showMatrix(matrixA,2,2);
	
	return 0;
}

//function defination

void showMatrix(double matrix[][10], int rows, int columns)
{
	for (int baris=0; baris<rows;baris++)
	{
		for (int kolum=0;kolum<columns;kolum++)
		{
			cout<< matrix[baris][kolum]<<"\t";
		}
		cout<<endl;
	}


}//end void showMatrix(double matrix[][10], int rows, int columns)



void setMatrix(double matrix[][10], int rows, int columns)
{
	for (int baris=0; baris<rows;baris++)
	{
		for (int kolum=0;kolum<columns;kolum++)
		{
			cout << "\t Enter item [ " << baris+1<<"]["<<kolum+1<<"] :";
			cin >> matrix[baris][kolum];
		}
	}


}//end void setMatrix(double matrix[][10], int rows, int columns)

# data[].attributes.body
latihan 1

# data[].attributes.attachment_link.readable_text
#include <iostream>
using namespace std;

int main()
{
	int x;

	cout << endl;
	cout << "Welcome to Programming Technique ....";
	cout << endl;
	
	cout << "Enter integer number: ";
	cin >> x;
	cout << "power 2 of the number: ";
	cout << x/2.0;
	cout << endl;
	return 0;
}

# data[].attributes.body
latihan 2

# data[].attributes.attachment_link.readable_text
// This program stores the address of a variable in a pointer
#include <iostream>
using namespace std;

int main()
 
{
		int x = 25;		// int variable
		int *ptr;		// pointer variable, can point to an int

		ptr = &x;		// store the address of x in ptr
		cout << " The value in x is " << x << endl;
		cout << " The address of x is " << &x << endl;

		cout << " The value in ptr is " << ptr << endl;
		cout << " The address of ptr is " << &ptr << endl;\
		cout << " Content of the address ptr is " << *ptr << endl;
		

		int *intptr = &x;		
	
		*intptr = 1000;
		cout << "\n The value in x is " << x << endl;
		
		// Array		
		int vals[] = {4, 7, 11};
		int *ptrvals;
		ptrvals = vals;

		cout << "\n The value in vals ="
				<< vals<< endl;

		cout << "\n The value in ptrvals ="
				<< ptrvals<< endl;

		//display content of the array
		cout << "\n Content of array vals = ";
		for (int index = 0; index<3; index++)
		
		{

		cout << vals [index] << " ";
		
		}
		cout << endl << endl;
		

		cout <<"\n Content of array vals =";
		for (int index = 0; index<3; index++)
		
		{

		cout << *(ptrvals++) << " ";
		
		}
		cout << endl << endl;
		
		return 0;
}

# data[].attributes.body
latihan 1

# data[].attributes.body
latihan 1