Programming Example
Programming Example
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int baris = 3;
const int lajur = 3;
string nama[] = { "Pelajar 1","Pelajar 2", "Pelajar 3","Pelajar 4" ,"Pelajar 5" };
string subjek[] = { "PR2","WEB","SAD" };
}}}}
void displayline(int a)
{
for (int i = 0; i < a; i++)
{
cout << "-";
}
cout << endl;
}
void paparGred(float& markah, float& jumlah, float& jum, float& A, float& A1, float& B, float& C, float& D, float& E)
{
float cg = 0;
jumlah += markah;
if (markah >= 0 && markah <= 39)
{
cout << " E ";
cg = 1.0;
E += 1;
}
else if (markah >= 40 && markah <= 46)
{
cout << " D ";
cg = 1.7;
D += 1;
}
else if (markah >= 47 && markah <= 59)
{
cout << " C ";
cg = 2.3;
C += 1;
}
else if (markah >= 60 && markah <= 74)
{
cout << " B ";
cg = 3.3;
B += 1;
}
else if (markah >= 75 && markah <= 100)
{
cout << " A ";
cg = 4.0;
A++;
A1 += 1;
}
jum += cg;
}
cout << " A = " << A << " | B = " << bcde[0] << " | C = " << bcde[1] << " | D = " << bcde[2] << " | E = " << bcde[3] << " | ";
cout << endl;
cout << "\t\t\t";
displayline(151);
}
cout << " Total A for " << subjek[0] << " = " << A1[0] << endl;
cout << " Total A for " << subjek[1] << " = " << A1[1] << endl;
cout << " Total A for " << subjek[2] << " = " << A1[2] << endl;
cout << endl;
float w[3];
w[0] = (A1[0] / baris) * 100;
w[1] = (A1[1] / baris) * 100;
w[2] = (A1[2] / baris) * 100;
for (int j = 0; j < lajur; j++)
{
cout << " The Percentage student A for " << subjek[j] << " = " << w[j] << " % " << endl;
if (w[j] >= 0 && w[j] < 40)
{
cout << endl;
cout << " Conclusion : Need to be Improve " << endl;
cout << endl;
}
else if (w[j] >= 40 && w[j] < 70)
{
cout << endl;
cout << " Conclusion : Good result!! " << endl;
cout << endl;
}
else if (w[j] >= 70 && w[j] <= 100)
{
cout << endl;
cout << " Conclusion : Excellent!! " << endl;
cout << endl;
}}}
cout << " Markah Paling TINGGI Untuk " << subjek[0] << " : " << tinggi[0] << endl;
cout << " " << nama[who[0]] << " memperolehi markah tertinggi untuk " << subjek[0] << endl;
cout << endl;
cout << " Markah Paling RENDAH Untuk " << subjek[0] << " : " << rendah[0] << endl;
cout << " " << nama[who[1]] << " memperolehi markah rendah untuk " << subjek[0] << endl;
cout << endl;
cout << " Markah Paling TINGGI Untuk " << subjek[1] << " : " << tinggi[1] << endl;
cout << " " << nama[who[2]] << " memperolehi markah tertinggi untuk " << subjek[1] << endl;
cout << endl;
cout << " Markah Paling RENDAH Untuk " << subjek[1] << " : " << rendah[1] << endl;
cout << " " << nama[who[3]] << " memperolehi markah rendah untuk " << subjek[1] << endl;
cout << endl;
cout << " Markah Paling TINGGI Untuk " << subjek[2] << " : " << tinggi[2] << endl;
cout << " " << nama[who[4]] << " memperolehi markah tertinggi untuk " << subjek[2] << endl;
cout << endl;
cout << " Markah Paling RENDAH Untuk " << subjek[2] << " : " << rendah[2] << endl;
cout << " " << nama[who[5]] << " memperolehi markah rendah untuk " << subjek[2] << endl;
int main()
{
float marks[baris][lajur];
int id_pelajar;
float markahP[lajur];
inputA(marks);
cout << "Pilih pelajar untuk di analisa : ";
cin >> id_pelajar;
determineByStudent(marks, markahP, id_pelajar);
determineBestLow(markahP, id_pelajar);
/*outputA(marks);
outputB(marks);*/
}
STRUCT EXAMPLE
#include <iostream>
#include<string>
struct Student{
string myString;
float markah;
}
void determineBest(Student b[])
{
float high = 0;
string namaTinggi = "y";
for (int i = 0; i < 2; i++)
{
if (high <= b[i].markah)
{
high = b[i].markah;
namaTinggi = b[i].myString;
}
}
cout << " The best student is " << namaTinggi << " with " << high << " marks "<< endl;
}
int main()
{
Student a[2];
for (int i = 0; i < 2; i++)
{
cout << " Please enter your name " << i + 1 << " : ";
cin >> a[i].myString;
cout << " Please enter your marks " << i + 1 << " : ";
cin >> a[i].markah;
}
cout<< " Display output :" << endl;
for (int i = 0; i < 2; i++)
{
cout << " Name " << i + 1 << " : ";
cout << a[i].myString << endl;
cout << " Marks " << i + 1 << " : ";
cout << a[i].markah << endl;
}
determineBest(a);
}
LAB TEST
#include <iostream>
#include <iomanip>
using namespace std;
void displayline(int a)
{
for (int i = 0;i < a;i++) //to display line
{
cout << "-";
}
cout << endl;
}
void output2()
{
cout << "Thank you for using this system!\n"; //to make the programme got 8 function
}
int main()
{
float bil[x], total,pay;
input(bil);
displayH(bil, total);
displayV(bil, total);
output(total, pay);
output2();
}
2D ARRAY EXAMPLE
#include <iostream>
#include <string>
using namespace std;
const int x = 4;
int main()
{
float mark[x][x];
float total[x];
int a;
input(mark, total);
output(mark, total,a);
output2(mark, a);
}
MIDTERM
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int x = 2;
const int y = 4;
void line(int l)
{
for (int i = 0; i < l; i++)
{
cout << "-";
}
cout << endl;
}
int main()
{
float markah[y][x];
float total[y];
input(markah, total);
display(markah, total);
}