Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 00f063f

Browse files
Add files via upload
1 parent 59531dc commit 00f063f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2303
-0
lines changed
79.3 KB
Binary file not shown.
84 Bytes
Binary file not shown.
16 Bytes
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<iostream>
2+
#include<fstream>
3+
using namespace std;
4+
class Person{
5+
string Name;
6+
unsigned short Age;
7+
8+
void Display()const{
9+
cout<<"\nName: "<<Name<<", Age: "<<Age<<endl;
10+
}
11+
public:
12+
Person(string Name="No Name Provided!\a",unsigned short Age=0):Name(Name),Age(Age){}
13+
14+
void Write_File_Data(){
15+
ofstream fout("Person.dat",ios::out|ios::binary);
16+
fout.write((char*)this,sizeof(Person));
17+
fout.close();
18+
}
19+
void Read_File_Data()const{
20+
ifstream fin("Person.dat",ios::in|ios::binary);
21+
if(!fin){
22+
cout<<"File not present!";
23+
return;
24+
}
25+
fin.read((char*)this,sizeof(Person));
26+
fin.close();
27+
Display();
28+
}
29+
};
30+
int main(){
31+
Person Person1("Shahzaib",21),Person2;
32+
Person1.Write_File_Data();
33+
Person2.Read_File_Data();
34+
return 0;
35+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include<iostream>
2+
using namespace std;
3+
#include<fstream>
4+
class Participant{
5+
char Name[20];
6+
unsigned int ID,Score;
7+
8+
void Input(){
9+
cout<<"Enter ID: ";
10+
cin>>ID;
11+
cout<<"Enter Name: ";
12+
cin>>Name;
13+
cout<<"Enter Score: ";
14+
cin>>Score;
15+
}
16+
void Display()const{
17+
cout<<"\nID: "<<ID<<", Name: "<<Name<<", Score: "<<Score<<endl;
18+
}
19+
public:
20+
Participant():Name{"N.i.l"},ID(0),Score(0){}
21+
void Input_Data(){
22+
Input();
23+
fstream f("Participant.dat",ios::app| ios::binary);
24+
f.write((char*)&*this,sizeof(*this));
25+
f.close();
26+
}
27+
static void Output_Data(){
28+
fstream f("Participant.dat",ios::in|ios::binary);
29+
if(!f){
30+
cout<<"file not present!"<<endl;
31+
return;
32+
}
33+
unsigned int _ID;
34+
cout<<"Enter ID to Find Record: ";
35+
cin>>_ID;
36+
Participant obj;
37+
while(f.read((char*)&obj,sizeof(obj))){
38+
if (_ID==obj.ID){
39+
obj.Display();
40+
break;
41+
}
42+
}
43+
f.close();
44+
}
45+
static void Max_Score(){
46+
fstream f("Participant.dat",ios::in|ios::binary);
47+
if(!f){
48+
cout<<"file not present!"<<endl;
49+
return;
50+
}
51+
Participant obj,max;
52+
while(f.read((char*)&obj,sizeof(obj)))
53+
if(obj.Score>max.Score)
54+
max=obj;
55+
f.close();
56+
max.Display();
57+
}
58+
};
59+
int main(){
60+
// Participant p1,p2,p3;
61+
// cout<<"p1 obj:-\n";
62+
// p1.Input_Data();
63+
// cout<<"p2 obj:-\n";
64+
// p2.Input_Data();
65+
// cout<<"p3 obj:-\n";
66+
// p3.Input_Data();
67+
// cout<<endl<<endl;
68+
Participant::Output_Data();
69+
cout<<"\n\nParticipant having Max Score:-\n";
70+
Participant::Max_Score();
71+
return 0;
72+
}
160 Bytes
Binary file not shown.
705 KB
Binary file not shown.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include<iostream>
2+
#include<fstream>
3+
#include<cstring>
4+
using namespace std;
5+
class Inventory{
6+
char Description[20];
7+
unsigned int Item_Code,Total_Units;
8+
float Rate_per_Unit;
9+
10+
void Display(unsigned short Item_Index)const{
11+
cout<<"Item "<<Item_Index<<":-\n"
12+
<<"Description: "<<Description<<endl
13+
<<"Item Code: "<<Item_Code<<endl
14+
<<"Total Units in Stock: "<<Total_Units<<endl
15+
<<"Rate per Unit: "<<Rate_per_Unit<<"\n\n";
16+
}
17+
public:
18+
Inventory(const char* Description="N.i.l",unsigned int Item_Code=0,unsigned int Total_Units=0,float Rate_per_Unit=0):
19+
Item_Code(Item_Code),Total_Units(Total_Units),Rate_per_Unit(Rate_per_Unit){ strcpy(this->Description,Description); }
20+
21+
void Update_Stock(unsigned short Item_Index){
22+
ofstream fout("Inventory.dat",ios::in|ios::ate|ios::binary);
23+
if(!fout){
24+
cout<<"File not Found!"<<"\n\n";
25+
return;
26+
}
27+
cout<<"Enter Total Units in Stock: ";
28+
cin>>Total_Units;
29+
fout.seekp((Item_Index-1)*sizeof(*this),ios::beg);
30+
fout.write((char*)this,sizeof(*this));
31+
fout.close();
32+
}
33+
static void Display_Details(unsigned int Code){
34+
Inventory obj;
35+
ifstream fin("Inventory.dat",ios::in|ios::binary);
36+
if(!fin){
37+
cout<<"File not Found!"<<"\n\n";
38+
return;
39+
}
40+
for(unsigned short i=0;fin.read((char*)&obj,sizeof(obj));++i){
41+
if (Code==obj.Item_Code){
42+
obj.Display(i+1);
43+
fin.close();
44+
return;
45+
}
46+
}
47+
cout<<"Item not Found!"<<"\n\n";
48+
fin.close();
49+
}
50+
static void Display_Details(){
51+
Inventory obj;
52+
ifstream fin("Inventory.dat",ios::in|ios::binary);
53+
if(!fin){
54+
cout<<"File not Found!"<<"\n\n";
55+
return;
56+
}
57+
for(unsigned short i=0;fin.read((char*)&obj,sizeof(obj));)
58+
obj.Display(++i);
59+
fin.close();
60+
}
61+
};
62+
int main(){
63+
Inventory obj[5]={Inventory("Blue-Band Butter",10101,1000,150), //i.e ctor's returns *this ptr
64+
Inventory("Brady's Bread",20202,500,60),
65+
Inventory("Desi Eggs",30303,450,99.9),
66+
Inventory("Bisconni Biscuits",40404,32,50),
67+
Inventory("Chips",50505,1200,20)};
68+
ofstream fout("Inventory.dat",ios::out|ios::binary);
69+
for(unsigned short i=0;i<5;++i)
70+
fout.write((char*)&obj[i],sizeof(obj[i]));
71+
fout.close();
72+
unsigned int choice;
73+
while(true){
74+
cout<<"Main-Menu:-\n^^^^^^^^^^^\n1) Update Specific Item Stock\n2) Display Specific Item Details\n3) Display all Items Details\n4) Exit\n==> ";
75+
cin>>choice;
76+
cin.clear();
77+
cin.sync();
78+
system("cls");
79+
switch(choice){
80+
case 1:
81+
cout<<"Enter Item Index: ";
82+
cin>>choice;
83+
obj[choice-1].Update_Stock(choice); //i.e. updates both file-data & within program-data
84+
break;
85+
case 2:
86+
cout<<"Enter Item Code: ";
87+
cin>>choice;
88+
Inventory::Display_Details(choice);
89+
break;
90+
case 3:
91+
Inventory::Display_Details();
92+
break;
93+
case 4:
94+
return 0;
95+
}
96+
}
97+
return 0;
98+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<iostream>
2+
using namespace std;
3+
template<class T>
4+
void Bubble_Sort(T arr[],int size){
5+
for (unsigned short i=0;i<size-1;++i){
6+
bool swapped=false;
7+
for (unsigned short j=0;j<size-1-i;++j){
8+
if (arr[j]>arr[j+1]){
9+
T temp=arr[j];
10+
arr[j]=arr[j+1];
11+
arr[j+1]=temp;
12+
swapped=true;
13+
}
14+
}
15+
if (!swapped)//i.e. break if no elements were swapped
16+
break;
17+
}
18+
}
19+
template<class T>
20+
void Display_Arr(T arr[],int size){
21+
for (unsigned short i=0;i<size;++i)
22+
cout<<arr[i]<<", ";
23+
}
24+
int main(){
25+
int arr[] {7,5,4,3,9,8,6},size=sizeof(arr)/sizeof(arr[0]);//Note: (no. of elements in arr)=(total arr size)/(arr data-type)
26+
Bubble_Sort(arr,size);
27+
cout<<"Sorted Integer Array: \n";
28+
Display_Arr(arr,size);
29+
float arr2[] {4.3,2.5,-0.9,100.2,3.0};
30+
size=sizeof(arr2)/sizeof(arr2[0]);
31+
Bubble_Sort(arr2,size);
32+
cout<<"\nSorted Float Array: \n";
33+
Display_Arr(arr2,size);
34+
return 0;
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
template<class T1,class T2=T1> //i.e. now same data-types can be written as one
4+
class Addition{
5+
T1 var1;
6+
T2 var2;
7+
public:
8+
Addition(T1 var1,T2 var2):var1(var1),var2(var2){}
9+
void Display_Addition()const{ cout<<"Addition: "<<var1+var2<<endl; }
10+
};
11+
template<>
12+
class Addition<char*>{
13+
string var1,var2;
14+
public:
15+
Addition(string var1,string var2):var1(var1),var2(var2){}
16+
void Display_Addition()const{ cout<<"Addition: "<<var1+var2<<endl; }
17+
};
18+
int main(){
19+
Addition<int,double> obj(10,0.23);
20+
obj.Display_Addition();
21+
Addition<char*> obj2("Now","Then");
22+
obj2.Display_Addition();
23+
return 0;
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /