forked from ReshmaMaharana/MyCodes
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAktardb.cpp
More file actions
155 lines (120 loc) · 3.03 KB
/
Aktardb.cpp
File metadata and controls
155 lines (120 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
using namespace std;
// CLASS DECLARATION
class DB
{
public:
void store();
void viewChronologically();
void sortbyPartID();
void viewbyPartID();
private:
class Part // This "public class" could also be a "struct" instead.
{
public:
int sl;
int ID;
float Price;
int Quantity;
Part(void){};
Part(int Partnum, float rate, int quant)
{
ID = Partnum;
Price = rate;
Quantity = quant;
} // DO: Initialize appropriately.
void store(int s)
{
sl = s;
// DO: Fill in prompts and input statements as indicated by the
cout << "Enter ID: ";
cin >> ID;
cout << "Enter Unit Price: ";
cin >> Price;
cout << "Enter Inventory Quantity: ";
cin >> Quantity;
// sample output:
};
void print()
{
cout << "Part ID: " << ID << "\tUnit Price = " << Price << "\t\tInventory = " << Quantity << endl;
};
};
Part n1, n2, n3;
Part *IDp1, *IDp2, *IDp3;
void swap(Part *a, Part *b);
void sortbyChronologicalOrder();
};
// CLASS DEFINITION
void DB::store()
{
cout << "Input ID, price, and quantity for three parts, as prompted" << endl;
cout << "Part 1:" << endl;
n1.store(1);
cout << "Part 2:" << endl;
n2.store(2);
cout << "Part 3:" << endl;
n3.store(3);
IDp1 = &n1;
IDp2 = &n2;
IDp3 = &n3;
// DO: Print a thank you message after storing as indicated in the
cout << "Thank you. The three parts have been securely stored in the database." << endl;
// sample output:
};
void DB::viewChronologically()
{
sortbyChronologicalOrder();
cout << "The three items in the database (in chronological order) are: " << endl;
n1.print();
n2.print();
n3.print();
};
// DO: Fill in the definition for the swap method in the DB class:
void DB::swap(DB::Part *a, Part *b)
{
Part temp;
temp = *a;
*a = *b;
*b = temp;
};
void DB::sortbyPartID()
{
if (IDp1->ID > IDp2->ID)
swap(IDp1, IDp2);
if (IDp2->ID > IDp3->ID)
{
swap(IDp2, IDp3);
if (IDp1->ID > IDp2->ID)
swap(IDp1, IDp2);
}
};
void DB::sortbyChronologicalOrder()
{
if (IDp1->sl > IDp2->sl)
swap(IDp1, IDp2);
if (IDp2->sl > IDp3->sl)
{
swap(IDp2, IDp3);
if (IDp1->sl > IDp2->sl)
swap(IDp1, IDp2);
}
}
void DB::viewbyPartID()
{
// DO: Fill in based on sample output:
cout << "The three items in the database (sorted by part ID) are:" << endl;
n1.print();
n2.print();
n3.print();
};
int main()
{
DB DB1;
DB1.store();
DB1.sortbyPartID();
DB1.viewbyPartID();
DB1.viewChronologically();
cout << "Have a good day! Bye!" << endl;
exit(0);
};