Week 11

11th Week(11th May 2013)

 

………………….

Hm? Oh, hello there! I didn’t see you there! Sorry for that. I was busy gawking at my perfect timing of uploading this page here. I guess you could say I feel very accomplished for the first time of my life! Harharharrr, what a loser I really am! Anyway, back to the relevant CPP stuff. So, we’ve made it to the 11th week since I’ve taken this course. 3 more weeks and we’re done! I get to celebrate by stuffing myself with lots of yummy carnivorous food! I can’t wait! But I think I’ll continue learning CPP on my own, instead of taking an extended course. It’ll be yet another torturous journey as a beginner still but that applies to any lessons in life anyway. Fact of life, hah! Oh, getting side-tracked again. Ok, this last week, we learnt more about 1-dimensional array and 2-dimensional array. The only way I can explain about 2-d array is that it is analogous to matrices in mathematics.

Instead of a row of boxes such as in 1-d array, in 2-d, we have a row and column of boxes. My mathematics teacher in my secondary school had this phrase drilled into my head and I still can’t forget this phrase to this day. “Row, Column, row, column, first is row, then column”. Well, you just need to manipulate the arrangement of your data as though they are going to be in a table form with their respective coordinates. Was what I just explained doesn’t make sense to you? Well, I can’t make sense of myself most of the time so you better be grateful this explanation is the only thing you don’t understand. Anyway, why don’t you have a look-sey at these programs I’ve made this week. The first one is a 1-dimensional array and the second one is a combination of 1-dimensional and 2-dimensional array. Have fun cringing! To think that you’d get used to see my horrid beginner’s programs by now….

#include <cstdlib>

#include <iostream>

#define i 6

 

/*

 

Nama: Nur Arina Bt Faizal      Program : Calculate Parking Fees Using Arrays

No Matrik: UK25837             Amali : Week 9

 

 

Algorithm;

Input: Input the types of vehicles; A, B, C and D

Process: 1) Using selective conditional statement ‘if’ and structure of ‘array’,

the     frequencies of the keyed in types of vehicles are sorted according

to each categories;

a)Number of lorries, NV[0]

b)Number of vans, NV[1]

c)Number of cars, NV[2]

d)Number of motorcycles, NV[3]

e)Number of unknown data, NV[4]

2) Given;

Type A: Lorries:                       RM60.00

Type B: Vans                           RM40.00

Type C: Cars:                           RM20.00

Type D: Motorcycles:  RM5.00

 

To calculate the total payment by the port authority;

PayA = NV[0] * 60.00

PayB = NV[1] * 40.00

PayC = NV[2] * 20.00

PayD = NV[3] * 5.00

 

TPay = PayA + PayB + PayC + PayD

Output: The output display is;

Total payment:                            RM ???

No. of lorries:                                          3

No. of vans:                                             1

No. of cars:                                              1

No. of motocycles:                                  0

No. of incorrect vehicle types::       1

 

*/

 

 

using namespace std;

void InitialData(); // Pengisytiharaan fungsi

void CalcData();

void DispData();

 

int Loop;

int N;

string T;

float NV[i];

float PayA;

float PayB;

float PayC;

float PayD;

float TPay;

 

 

int main(int argc, char *argv[])

{

 

InitialData(); // Declare functions

CalcData();

DispData();

system(“PAUSE”);

return EXIT_SUCCESS;

}

 

void InitialData() // Initialise data for summing the no. of vehicle in the next void

{

cout << “\n      ************ Amali Minggu 9 ************” << endl;

cout << ”    *********** Calculate Parking Fees ***********” << endl;

cout << ”  ******* Nama : Nur Arina Bt Faizal Abdullah *******” << endl;

cout << “**************** Matrik No : UK25837 *******************” << endl << endl << endl;

for (N = 0; N < i; N++)

{

NV[N] = 0;

}

}

 

void CalcData() // Input and calculating the data

{

cout << “\nType in the types of vehicles in the port via a, b, c, d ” << endl;

cout << “\nRepeat the action if there is more than 1 vehicle for a certain type: ”

<< endl;

 

for (Loop = 0; Loop < i; Loop++)

{

cin >> T; // User key in the type of vehicle(s)

if (T == “a” ) // If user type in ‘a’, then NV with ‘address 0’ will increase its value by 1

NV[0]++;

else if (T == “b” )

NV[1]++;

else if (T == “c” )

NV[2]++;

else if (T == “d” )

NV[3]++;

else NV[4]++;

}

 

//To calculate the total payment by the port authority;

PayA = NV[0] * 60.00;

PayB = NV[1] * 40.00;

PayC = NV[2] * 20.00;

PayD = NV[3] * 5.00;

 

TPay = PayA + PayB + PayC + PayD;

}

 

void DispData() // Display all relevant results and data

{

cout << “\nTotal payment: RM ”              << TPay << endl << endl;

cout << “No. of lorries:        ”                        << NV[0] << endl << endl;

cout << “No. of vans: ”                   << NV[1] << endl << endl;

cout << “No. of cars:            ”                                << NV[2] << endl << endl;

cout << “No. of motocycles: ”                   << NV[3] << endl << endl;

cout << “No. of incorrect vehicle types: “<< NV[4] << endl;

 

}

 

NEXT PROGRAM!!!!!

#include <cstdlib>

#include <iostream>

 

 

/*

Nama: Nur Arina Bt Faizal      Program : Kira Gaji Menggunakan Tatasusunan 2D

No Matrik: UK25837             Amali : Minggu 10

 

MASALAH:

 

Syarikat Madyazkom Sdn Bhd meminta anda menyelesaikan masalah Pengiraan Gaji SEKUMPULAN pekerja syarikat tersebut. Setiap pekerja mempunyai satu nombor kakitangan.  Jumlah gaji pekerja terdiri dari gaji asas, elaun overtime dan elaun perumahan. Gaji akan dikenakan potongan cukai  mengikut gaji penunya mengikut syarat berikut:

 

 

SEMUA pemprosesan dalam dilakukan ke atas data dalam tatasusunan ini.

 

* Data input hendaklah dibaca ke dalam dua tatasusuna:

(a) 1 tatasusunan 1-DIMENSI  untuk memegang 100 nombor pekerja yang terdiri dari nombor kad pengenalan pekerja.

(b) 1 tatasusunan 2-DIMENSI maksima 100 pekerja (100 X 5).  Setiap lajur dalam tatasusunan 2-DIMENSI ini pula terdiri dari gaji_asas,  elaun_overtime dan elaun_rumah.  Dari data input ini,  jumlah gaji & potongan bulanan akan dikira dan disimpan dalam Lajur ke-4 & 5.

 

Jumlah gaji dikira  dengan menjumlahkan gaji_asas,  elaun_overtime dan elaun_rumah.  Ini disimpan dalam lajur 4.  Dari jumlah ini, kira potongan bulanan dan disimpan dalam lajur 5.

 

*** Pamer output ke skrin di akhir pemprosesan.

 

Contoh data input;

 

Kad-pengenalan          gaji                  elaun-OT         elaun-rumah

700121-11-1345          800.0               125.00             300.00

711204-11-1344          1200.00               280.00                     300.00

<tambah dengan lain data>

751101-11-3345          800.0               125.00             300.00

0                                  0                      0                      0                      <<< pengakhir data pekerja

 

 

 

Algoritma Umum:

Input: Data yang perlu diinputkan;

a) Nombor kad pengenalan, KP[i]

b) Gaji asas, P[i][0]

c) Elaun Overtime, P[i][1]

d) Elaun rumah, P[i][2]

Proses:

1) Susunkan data mengikut urutan yang sesuai.

 

2) Tambahkan semua gaji;

P[i][3] = P[i][0] + P[i][1] + P[i][2]

 

3) Kira potongan gaji dengan menggunakan arahan bersyarat ‘if’;

a) Jika jumlah gaji RM1000.00 atau kurang, tiada cukai;

P[i][4] = P[i][3] * 0;

b) Jika jumlah gaji RM2000.00 atau kurang, cukai ialah

10% dari jumlah gaji;

P[i][4] = P[i][3] * 0.1;

c) Jika jumlah gaji RM2001.00 ke atas, cukai ialah 20%

dari jumlah gaji;

P[i][4] = P[i][3] * 0.2;

4) Tolakkan jumlah gaji dengan jumlah gaji potongan;

P[i][5] = TP[i][3] – P[i][4]

5) Ulangi arahan menggunakan arahan ulangan ‘while’.

 

Output: Pamerkan;

a) Nombor kad pengenalan, KP[i]

b) Gaji asas, P[i][0]

c) Elaun Overtime, P[i][1]

d) Elaun rumah, P[i][2]

e) Jumlah gaji, P[i][3]

f) Jumlah potongan gaji, P[i][4]

g) Jumlah gaji selepas potongan, P[i][5]

*/

 

 

using namespace std;

void BacaData();

void KiraJumlahGaji();

void KiraPotonganGaji();

void PamerHasil();

 

int total;

int i ;

int j ;

string KP[100];

float P[100][5];

 

 

 

int main(int argc, char *argv[])

{

 

BacaData(); // Declare functions

KiraJumlahGaji();

KiraPotonganGaji();

PamerHasil();

system(“PAUSE”);

return EXIT_SUCCESS;

}

 

void BacaData() // Initialise data for summing the no. of vehicle in the next void

{

cout << “\n\t      ************ Lab Week 10 ************” << endl;

cout << “\t     ****** Calculate Salaries (2D Array) ********” << endl;

cout << “\t  ******* Nama : Nur Arina Bt Faizal Abdullah *******” << endl;

cout << “\t**************** Matrik No : UK25837 *******************” << endl << endl << endl;

 

cout << “\t    *-*-*-* Syarikat Madyazkom Sdn Bhd *-*-*-* ” << endl << endl << endl;

cout << “\nJumlah pekerja: “;

cin  >> total;

i = 0;

while (i < total)

{

i++;

}

}

 

void KiraJumlahGaji() // Input and calculating the data

{

 

for (i = 0; i < total; i++)

{

cout << “\nSila masukkan nombor kad pengenalan : ” << endl;

cin  >> KP[i];

cout << “\nSila masukkan nilai gaji untuk 1 pekerja; ” << endl;

cout << “\nGaji asas : ” << endl;

cin  >> P[i][0];

cout << “\nElaun overtime : ” << endl;

cin  >> P[i][1];

cout << “\nElaun rumah : ” << endl;

cin  >> P[i][2];

P[i][3] = P[i][0] + P[i][1] + P[i][2];

}

}

void KiraPotonganGaji()

{

for (i = 0; i < total; i++)

{

if (P[i][3] <= 1000.00 )

P[i][4] = 0;

if (P[i][3] >= 1001.00  && P[i][3] <= 2000.00 )

P[i][4] = P[i][3] * 0.1;

if (P[i][3] >= 2001.00 )

P[i][4] = P[i][3] * 0.2;

P[i][5] = P[i][3] – P[i][4];

}

 

}

 

void PamerHasil() // Display all relevant results and data

{

cout << “\nNo Kad Pengenalan\t” ;

cout << “Gaji Asas\t” ;

cout << “Elaun Overtime\t” ;

cout << ”   Elaun Rumah” << endl << endl;

for (i = 0; i < total; i++)

{

 

cout << KP[i] << “\t\t  “;

cout << P[i][0] << “\t\t”;

cout << P[i][1] << “\t\t\t”;

cout << P[i][2] << endl << endl << endl;

 

}

cout << “\nJumlah Gaji\t\t” ;

cout << “Jumlah Potongan Gaji\t   ” ;

cout << “Jumlah Gaji ” << endl;

 

cout << “(Sebelum Potongan)\t\t\t\t” ;

cout << “(Selepas Potongan) ” << endl << endl;

for (i = 0; i < total; i++)

{

 

cout << P[i][3] << “\t\t\t”;

cout << P[i][4] << “\t\t\t\t”;

cout << P[i][5]  << endl << endl;

 

}

}

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s