0% found this document useful (0 votes)
3 views

class.cpp

Uploaded by

lysarith09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

class.cpp

Uploaded by

lysarith09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Review\class.

cpp

1 #include<iostream>
2 using namespace std;
3 //Class: បណ្ដុំ របស់ Class Members:
4 //1- Attributes / Properties / Data Members: ទិន្នន័យ
5 //2- Method / Function / Member Function": កម្មវិធីសំរាប់ដំណើ រការ ឬបំលែងទិន្នន័យ
6 //បង្កើត Class
7 class Product{
8 //1- Attributes / Properties / Data Members: ទិន្នន័យ
9 protected://នាំចេញទៅពិភពខាងក្រៅតាម Public Method
10 int pro_id;
11 string pro_name;
12 private://នាំចេញទៅពិភពខាងក្រៅតាម Public Method
13 float price;
14 int qty;
15 float total;
16 float discount;
17 float paid;
18 //2- Method / Function / Member Function": កម្មវិធីសំរាប់ដំណើ រការ ឬបំលែងទិន្នន័យ
19 public:
20 //Public Methods
21 //កំណត់តំលៃឲ្យ Properties
22 void set(int par_id, string par_name, float par_price, int par_qty){
23 pro_id = par_id;
24 pro_name = par_name;
25 price = par_price;
26 qty = par_qty;
27 }
28 //រកតំលៃសរុប(total)
29 void find_total(){
30 total = price * qty;
31 }
32 //រកបញ្ចុះតំលៃ(ប្រសិនបើ total លើស 400 បញ្ចុះតំលៃ 5%)
33 void find_discount(){
34 if(total > 400){
35 discount = total * 0.05;
36 }else{
37 discount = 0;
38 }
39 }
40 //រកប្រាក់ចំណាយ(ប្រសិនបើ total លើស 400 បញ្ចុះតំលៃ 5%)
41 void find_paid(){
42 paid = total - discount;
43 }
44 //បង្ហា ញលទ្ធផលរបស់ Properties ទៅលើ Screen
45 void print(){
46 cout << "-------------------------" << endl;
47 cout << "Product ID: " << pro_id << endl;
48 cout << "Product Name: " << pro_name << endl;
49 cout << "Price: " << price << endl;
50 cout << "Qty: " << qty << endl;
51 cout << "Total: " << total << endl;
52 cout << "Discount: " << discount << endl;
53 cout << "Paid: " << paid << endl;
54 cout << "-------------------------" << endl;
55 }
56 };
57 int main(){
58 //បង្កើត Object
59 Product Itm;
60 //Accessing to Class Members
61 //Itm.pro_id = 12;//Protected: Inaccessible
62 //Itm.price = 120;//Private: Inaccessible
63 Itm.set(7, "ABC", 450.45, 2);
64 Itm.find_total();
65 Itm.find_discount();
66 Itm.find_paid();
67 Itm.print();
68 cout << "-------------------------" << endl;
69 Itm.set(9, "Xyz", 650.55, 5);
70 Itm.find_total();
71 Itm.find_discount();
72 Itm.find_paid();
73 Itm.print();
74 return 0;
75 }

You might also like