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
|
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
for(;1;)
{
rerun:
system("CLS");
int ch;
char name[30];
cout<<"**********Welcome to Courier Service**********\n\n\n";
cout<<"\t\t:::Main Menu:::\n";
cout<<"\n"<<"1. Create Order";
cout<<"\n"<<"2. Trace Order";
cout<<"\n"<<"3. Modify Order Status";
cout<<"\n"<<"4. Expedite Order";
cout<<"\n"<<"5. Delete Order";
cout<<"\n"<<"6. Exit";
cout<<"\n \n"<<"Enter Choice::";
cin>>ch;
switch(ch)
{
case 1:
{
system("CLS");
cout<<"**********Welcome to Courier Service**********\n\n\n";
cout<<"\t\t:::Create Order Menu:::\n";
ofstream outfl;
outfl.open("order.txt",ios::app);
cout<<"\n"<<"1. Order No::";
gets(name);
gets(name);
outfl<<"#";
outfl<<name;
outfl<<'%';
cout<<"\n"<<"2. Order Owner::";
gets(name);
outfl<<name;
outfl<<'%';
cout<<"\n"<<"3. Order Weight::";
gets(name);
outfl<<name;
outfl<<'%';
cout<<"\n"<<"4. Order Due Date::";
gets(name);
outfl<<name;
outfl<<'^';
cout<<"\n"<<"5. Order Status::";
gets(name);
outfl<<name;
outfl<<'\n';
outfl.close();
break;
}
case 2:
{
search:
system("CLS");
cout<<"**********Welcome to Courier Service**********\n\n\n";
cout<<"\t\t:::Trace Order Menu:::\n\n";
string line;
string word;
size_t i;
int offset;
ifstream dict;
dict.open("order.txt",ios::in);
cout<<"\n"<<"Enter Order No::";
cin>>word;
word.insert(0,"#");
while (!dict.eof())
{
string OrderNo;
string OwnerName;
string OrderWeight;
string OrderDueDate;
string OrderStatus;
for(;!dict.eof();)
{
getline(dict, OrderNo, '%' );
getline(dict, OwnerName, '%');
getline(dict, OrderWeight, '%');
getline(dict, OrderDueDate, '^');
getline(dict, OrderStatus, '\n');
if (OrderNo.compare(word)== 0)
{
cout<<"OrderNo: "<<OrderNo<<endl;
cout<<"OwnerName: "<<OwnerName<<endl;
cout<<"OrderWeight: "<<OrderWeight<<endl;
cout<<"OrderDueDate: "<<OrderDueDate<<endl;
cout<<"OrderStatus: "<<OrderStatus<<endl;
}
else
break;
}
}
looper:
dict.close();
cout<<"\n\nTo search another order type 'Y' or to go back to Main Menu type 'N'\n\nEnter Choice::";
cin>>word;
if(word.compare("Y")==0 || word.compare("y")==0)
goto search;
else if (word.compare("N")==0 || word.compare("n")==0)
goto rerun;
break;
}
case 3:
{
int found;
long pos;
string word;
string line;
string status;
fstream myfile;
system("CLS");
cout<<"**********Welcome to Courier Service**********\n\n\n";
cout<<"\t\t:::Trace Order Menu:::\n\n";
cout<<"\n"<<"Enter Order No::";
cin>>word;
word.insert(0,"#");
myfile.open ("order.txt", ios::in | ios::out);
string OrderNo;
string OwnerName;
string OrderWeight;
string OrderDueDate;
string OrderStatus;
while (!myfile.eof())
{
for(;!myfile.eof();)
{
getline(myfile, OrderNo, '%' );
getline(myfile, OwnerName, '%');
getline(myfile, OrderWeight, '%');
getline(myfile, OrderDueDate, '^');
getline(myfile, OrderStatus, '\n');
if (OrderNo.compare(word)== 0)
{
cout<<"OrderNo: "<<OrderNo<<endl;
cout<<"OwnerName: "<<OwnerName<<endl;
cout<<"OrderWeight: "<<OrderWeight<<endl;
cout<<"OrderDueDate: "<<OrderDueDate<<endl;
cout<<"OrderStatus: "<<OrderStatus<<endl;
}
else
break;
}
}
cout<<"\n\nTo change order status type 'C'\nTo search another order type 'Y'\nOr to go back to Main Menu type 'N'\n\nEnter Choice::";
cin>>word;
if(word.compare("Y")==0 || word.compare("y")==0)
goto search;
else if (word.compare("N")==0 || word.compare("n")==0)
goto rerun;
else if (word.compare("C")==0 || word.compare("c")==0)
{
cout<<"\n"<<"Enter New Status::";
cin>>status;
if (myfile.is_open())
{
while( getline(myfile,line) )
{
found = line.find(OrderStatus);
if (found >= 0)
{
pos = myfile.tellg(); // Somewhere around here
cout<<pos<<endl;
line.replace(found, OrderStatus.size(),status);
cout<<line;
}
}
myfile.close();
}
else
cout << "Unable to open file";
return 0;
}
}
case 6:
{
exit(1);
}
}
}
return 1;
}
|