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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
class student
{
private :
string name;
string department;
string id;
int year;
public:
student(){}
student(string n,string ID,string dep,int y)
{
name=n;
department=dep;
id=ID;
year=y;
}
void setAll(string n,string ID,string dep,int y)
{
name=n;
department=dep;
id=ID;
year=y;
}
void print()
{
cout<<"Name : "<<name<<endl;
cout<<"Department : "<<department<<endl;
cout<<"ID : "<<id<<endl;
cout<<"Birth Year : "<<year<<endl;
}
};
class book
{
private :
string name;
string id;
string author;
string available;
public:
book(){}
book(string n,string ID,string a,string av)
{
name=n;
id=ID;
author=a;
available=av;
}
void setAll(string n,string ID,string a,string av)
{
name=n;
id=ID;
author=a;
available=av;
}
void print()
{
cout<<"Name : "<<name<<endl;
cout<<"Department : "<<author<<endl;
cout<<"ID : "<<id<<endl;
cout<<"Birth Year : "<<available<<endl;
}
};
class borrow
{
private :
string id;
string bookID;
public:
borrow(){}
borrow(string ID,string bid)
{
id=ID;
bookID=bid;
}
void setAll(string ID,string bid)
{
id=ID;
bookID=bid;
}
};
void loadBook(vector<book> &b)
{
ifstream myFile;
string temp,name,id,a,av;
int pos,pos2,pos3;
int x=0;
myFile.open("book.txt");
while(!myFile.eof())
{
getline(myFile,temp);
pos=temp.find(':');
name=temp.substr(0,pos);
pos2=temp.find(':',pos+1);
id=temp.substr(pos+1,pos2-pos-1);
pos3=temp.find(':',pos2+1);
a=temp.substr(pos2+1,pos3-pos2-1);
av=temp.substr(pos3+1,temp.size()-pos3);
b[x].setAll(name,id,a,av);
x++;
}
}
void loadBorrow(vector<borrow>&bor)
{
ifstream myFile;
string temp,id,bid;
int pos,pos2;
int x=0;
myFile.open("borrow.txt");
while(!myFile.eof())
{
getline(myFile,temp);
pos=temp.find(':');
id=temp.substr(0,pos);
pos2=temp.find(':',pos+1);
bid=temp.substr(pos+1,temp.size()-pos);
bor[x].setAll(id,bid);
x++;
}
}
void loadStu(vector<student>&stu)
{
ifstream myFile;
string temp,name,id,dep,y;
int year,pos,pos2,pos3;
int x=0;
myFile.open("student.txt");
while(!myFile.eof())
{
getline(myFile,temp);
pos=temp.find(':');
name=temp.substr(0,pos);
pos2=temp.find(':',pos+1);
id=temp.substr(pos+1,pos2-pos-1);
pos3=temp.find(':',pos2+1);
dep=temp.substr(pos2+1,pos3-pos2-1);
y=temp.substr(pos3+1,temp.size()-pos3);
year=atoi(y.c_str());
stu[x].setAll(name,id,dep,year);
x++;
}
for(int i=0;i<x;i++)
stu[i].print();
}
int _tmain(int argc, _TCHAR* argv[])
{
int x=5;
int r,pos,year,i;
string name,id,dep,y,sil;
vector<student> stu;
vector<book>b;
vector<borrow>bor;
stu.resize(10);
b.resize(10);
bor.resize(10);
size_t found;
cout<<"Ne yapmak istersiniz?"
<<"\nekleme için 1"
<<"\nsilmek icin 2"
<<endl;
cin>>r;
while(!(r==1 || r==2 || r==3))
{
cout<<"Ne yapmak istersiniz?"
<<"\nEkleme yapmak icin 1'i"
<<"\nsilmek icin 2'yi"
<<endl;
cin>>r;
}
if(r==1)
{
cout<<"Lütfen ismi giriniz"<<endl;
cin>>name;
cout<<"Lütfen bolumu giriniz"<<endl;
cin>>dep;
cout<<"Lütfen numarayi giriniz"<<endl;
cin>>id;
cout<<"Lütfen yili giriniz"<<endl;
cin>>y;
year=atoi(y.c_str());
x=x+1;
stu[x].setAll(name,id,dep,year);
freopen ("student.txt","a+",stdout);
cout<<stu[x];
fclose (stdout);
}
else
{
cout<<"Lütfen numarayi giriniz"<<endl;
cin>>sil;
for(i=0;i<x;i++)
{
if(sil==stu[i].id)
stu[i].setAll("Bu kayit silinmistir");
}
}
loadStu(stu);
loadBook(b);
loadBorrow(bor);
for(int i=0;i<x;i++)
{
stu[i].print();
//b[i].print();
//bor[i].print();
}
system("PAUSE");
return 0;
}
|