-
Notifications
You must be signed in to change notification settings - Fork 0
/
LA6.cpp
126 lines (114 loc) · 2.35 KB
/
LA6.cpp
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
#include<bits/stdc++.h>
using namespace std;
typedef struct rec
{
char item_name[20];
int item_code;
int quantity;
float cost;
}node;
node temp;
list < node > lst;
list < node > ::iterator ptr;
bool operator <(node &p,node &q)
{
if(p.item_code<q.item_code)
return true;
else
return false;
}
void Create()
{
int n,i;
cout<<"\n How many elements you want to insert?"<<endl;
cin>>n;
cout<<"\n Enter the Elements in the List"<<endl;
for(i=0;i<n;i++)
{
cout<<"\n Item code:";
cin>>temp.item_code;
cout<<"\n Item Name:";
cin>>temp.item_name;
cout<<"\n Quantity:";
cin>>temp.quantity;
cout<<"\n Cost:";
cin>>temp.cost;
lst.push_back(temp);
}
}
void Display()
{
cout<<"\n\t The contents of the List are:";
cout<<"\n******************************************************";
cout<<"\n Item Code Item Name Quantity Cost";
cout<<"\n*******************************************************";
for(ptr=lst.begin();ptr!=lst.end();ptr++)
{
cout<<"\n";
cout<<" "<<(*ptr).item_code;
cout<<" "<<(*ptr).item_name;
cout<<" "<<(*ptr).quantity;
cout<<" "<<setw(4)<<(*ptr).cost;
}
}
void Searching()
{
int key;
int flag=0;
cout<<"\n Enter the element which you want to search";
cin>>key;
for(ptr=lst.begin();ptr!=lst.end();ptr++)
{
if((*ptr).item_code==key)
{
flag=1;
break;
}
else
flag=0;
}
if(flag==1)
cout<<"\n The desired element is present in the list";
else
cout<<"\n The desired element is not present in the list";
}
void Sorting()
{
lst.sort();
cout<<"\n\n Record is Sorted!!!"<<endl;
}
int main()
{
char ans='y';
int choice;
cout<<"\n Program for Searching and sorting";
do
{
cout<<"\n Main Menu ";
cout<<"\n 1. Create a list";
cout<<"\n 2. Display a list";
cout<<"\n 3. Search particular element";
cout<<"\n 4. Sort the list";
cout<<"\n Enter your choice";
cin>>choice;
switch(choice)
{
case 1:
Create();
break;
case 2:
Display();
break;
case 3:
Searching();
break;
case 4:
Sorting();
Display();
break;
}
cout<<"\n Do you want to go back to Main Menu?";
cin>>ans;
}while(ans=='y');
return 0;
}