Skip to content

Commit b4973f2

Browse files
committed
feat : STL added
1 parent adb9553 commit b4973f2

File tree

6 files changed

+110
-9
lines changed

6 files changed

+110
-9
lines changed

18.IO Streams/a.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

18.IO Streams/product.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

18.IO Streams/student.txt

Whitespace-only changes.

19.STL/1_demo_stl_classes.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# include<iostream>
2+
# include<vector>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
vector<int> v={2,4,6,8,10};
8+
v.push_back(20);
9+
v.push_back(30);
10+
vector<int>::iterator itr;
11+
cout<<"using iterator"<<endl;
12+
for(itr=v.begin();itr!=v.end();itr++)
13+
cout<<++*itr<<endl;
14+
cout<<"using for each loop"<<endl;
15+
for(int x:v)
16+
cout<<x<<endl;
17+
}

19.STL/2_map_classes.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# include<iostream>
2+
# include<map>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
map<int,string> m;
8+
m.insert(pair<int,string>(1,"Micheal"));
9+
m.insert(pair<int,string>(2,"Jim"));
10+
m.insert(pair<int,string>(3,"Dwight"));
11+
map<int,string>::iterator itr;
12+
for(itr=m.begin();itr!=m.end();itr++)
13+
{
14+
cout<<itr->first<<" "<<itr->second<<endl;
15+
}
16+
map<int,string>::iterator itr1;
17+
itr1=m.find(2);
18+
cout<<"value at 2:"<<endl;
19+
cout<<itr1->first<<" "<<itr1->second<<endl;
20+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include<iostream>
2+
#include<fstream>
3+
#include<vector>
4+
using namespace std;
5+
6+
class Item{
7+
private:
8+
string name;
9+
float price;
10+
int qty;
11+
public:
12+
Item(){}
13+
Item(string n,float p,int q);
14+
friend ifstream & operator>>(ifstream &fis,Item &i);
15+
friend ofstream & operator<<(ofstream &fos,Item &i);
16+
friend ostream & operator<<(ostream &os,Item &i);
17+
18+
};
19+
20+
Item::Item(string n,float p,int q){
21+
name=n;
22+
price=p;
23+
qty=q;
24+
}
25+
26+
ofstream & operator<<(ofstream &fos,Item &i){
27+
fos<<i.name<<endl<<i.price<<endl<<i.qty<<endl;
28+
return fos;
29+
}
30+
31+
ifstream & operator>>(ifstream &fis,Item &i){
32+
fis>>i.name>>i.price>>i.qty;
33+
return fis;
34+
}
35+
36+
ostream & operator<<(ostream &os,Item &i){
37+
os<<i.name<<endl<<i.price<<endl<<i.qty<<endl;
38+
return os;
39+
}
40+
41+
int main(){
42+
int n;
43+
string name;
44+
float price;
45+
int qty;
46+
47+
cout<<"Enter number of Item:";
48+
cin>>n;
49+
50+
vector<Item *> list;
51+
cout<<"Enter All Item "<<endl;
52+
for(int i=0;i<n;i++){
53+
cout<<"Enter "<<i+1<<" Item Name , price and quantity";
54+
cin>>name;
55+
cin>>price;
56+
cin>>qty;
57+
list.push_back(new Item(name,price,qty));
58+
}
59+
60+
ofstream fos("items.txt");
61+
vector<Item *>::iterator itr;
62+
63+
for(itr=list.begin();itr!=list.end();itr++){
64+
fos<<**itr;
65+
}
66+
67+
Item item;
68+
ifstream fis("items.txt");
69+
for(int i=0;i<n;i++){
70+
fis>>item;
71+
cout<<"Item "<<i<<endl<<item<<endl;
72+
}
73+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy