-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhandphone.cpp
More file actions
70 lines (63 loc) · 1.96 KB
/
handphone.cpp
File metadata and controls
70 lines (63 loc) · 1.96 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
//C++ program that interactively accepts and stores the information of used handphones for sale
#include <iostream>
#include <string>
using namespace std;
struct Phones //structure of Phone
{
string make, model;
int price;
char condition;
};
void storeInfo(int, Phones []); //prototype deceleration
void sortInfo(int, Phones []); //prototype deceleration
void displayInfo(int, Phones []); //prototype deceleration
int main() // main Function
{
Phones myphone[8] = {};
int numphones;
cout << "Please enter number of phones for sale: " ;
cin >> numphones;
storeInfo(numphones,myphone); // calling storeinfo function that store information
sortInfo(numphones,myphone); // calling sortinfo function that sort information
displayInfo(numphones,myphone); // calling displayinfo function that print information
return 0;
}
void storeInfo(int nphones, Phones rec[])
{
cout << nphones;
for (int i = 0; i < nphones; i++) {
cout << "Please enter Phone Manufacturer: " ;
cin >> (rec+i)->make;
cout << "Please enter Phone Model: " ;
cin >> (rec+i)->model;
cout << "Please enter price of car: " ;
cin >> (rec+i)->price;
cout << "Please enter Condition Grade A,B or C: " ;
cin >> (rec+i)->condition;
cout << endl;
}
}
void sortInfo(int nphones, Phones info[])
{
//find the logical error here
Phones temp;
cout << "Make\t\tModel\tPrice\tCondition\n" ;
cout << "------\t\t-----\t---\t--------\n" ;
for (int i = 0; i < nphones-1; i++)
{
for(int j=0; j <(nphones-i-1);j++)
{
if((info+j)->price>(info+i+1)->price){
temp = *(info+j);
*(info+j) = *(info+j+1);
*(info+j+1) = temp;
}
}
}
}
void displayInfo(int nphones, Phones info[]){
for(int i = 0; i < nphones; i++){
cout << (info+i)->make << "\t\t" << (info+i)->model << "\t"
<< (info+i)->price << "\t" << (info+i)->condition << endl;
}
}