完整的代码是正确的,但我在第28行只得到了这一个错误:declaration terminated incorrectly
。
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<iostream.h>
class Rail
{
private:
char GetYN();
struct Train
{
int tno, nop;
char tname[50];
char dest[50];
float dist, fare;
}t;
public:
void Input();
void CreateFile();
void Display();
void Search();
void Modify();
void Delete();
void AddRecord();
}R;
void introduction();
{ \\This is where the error is (error: declaration terminated incorrectly)
clrscr()
cout << "\n\n";
cout << "\t =============================================================\n";
cout << "\t ** **\n";
cout << "\t ** WELCOME TO **\n";
cout << "\t ** METRO **\n";
cout << "\t ** RAILWAY MANAGEMENT SYSTEM **\n";
cout << "\t ** **\n";
cout << "\t ** PROGRAMMED BY:- **\n";
cout << "\t ** ---------------- **\n";
cout << "\t ** Waqar **\n";
cout << "\t ** **\n";
cout << "\t ** Std: XII Div: A **\n";
cout << "\t ** **\n";
cout << "\t ** INDIAN CENTRAL SCHOOL **\n";
cout << "\t ** KUWAIT **\n";
cout << "\t ** **\n";
cout << "\t =============================================================\n";
cout << "\n\n\t Press any key to view the Main Menu.";
getch();
}
char Rail::GetYN()
{
char ch;
do
{
ch = getch();
} while ((ch != 'Y'&&ch != 'y') && (ch != 'N'&&ch != 'n'))
return ch;
}
void Rail::Input()
{
cout << "\nEnter the train number: ";
cin >> t.tno;
cout << "\nEnter the no of pasengers: ";
cin >> t.nop;
cout << "\nEnter the train name: ";
gets(t.tname);
cout << "\nEnter the destination: ";
gets(t.dest);
cout << "\nEnter the distance: ";
cin >> t.dist;
cout << "\nEnter the fare: ";
cin >> t.fare;
}
void Rail::CreateFile()
{
char ContinueYN;
fstream DataFile;
DataFile.open("Train.dat", ios::out | ios::binary);
do
{
clrscr()
Input;
DataFile.write((char*)&t, sizeof(t));
cout << "\nDo you want to enter another record [y/n]";
ContinueYN = GetYN();
} while (ContinueYN == 'y' || ContinueYN == 'Y');
DataFile.close();
}
void Rail::Display()
{
fstream DataFile;
DataFile.open("Train.dat", ios::binary | ios::in);
DataFile.read((char*)&t, sizeof(t));
clrscr()
while (!DataFile.eof())
{
cout << "\nTrain no: " << t.tno;
cout << "\nNo of Passengers: " << t.nop;
cout << "\nTrain name: " << t.tname;
cout << "\nDestination: " << t.dest;
cout << "\nDistance: " << t.dist;
cout << "\nFare: " << t.fare;
cout << "\n\n ";
cout << "\nPress any key to continue..";
getch();
clrscr();
DataFile.read((char*)&t, sizeof(t));
}
DataFile.close();
}
void Rail::Search()
{
int IdToSearchFor, found = 0;
clrscr()
cout << "\nEnter the train number to be searched: ";
cin >> IdToSearchFor;
fstream DataFile;
DataFile.open("Train.dat", ios::binary | ios::in);
do
{
DataFile.read((char*)&t, sizeof(t));
if (t.tno == IdToSearchFor)
{
cout << "\nNo. of Passengers: " << t.nop;
cout << "\nTrain name: " << t.tname;
cout << "\nDestination: " << t.dest;
cout << "\nDistance: " << t.dist;
cout << "\nFare: " << t.fare;
cout << "\n\n";
found = 1;
break;
}
} while (!DataFile.eof());
if (found == 0)
{
cout << "\nRecord not found!";
}
cout << "\nPress any key to continue.";
getch();
}
void Rail::Modify()
{
fstream DataFileo;
int IdToSearchFor, found = 0;
char ModifyYesNo;
clrscr()
cout << "\nEnter train number of train whose details you want to modify: ";
cin >> IdToSearchFor;
fstream DataFilei;
DataFilei.open("Train.dat", ios::binary | ios::in);
do
{
DataFilei.read((char*)&t, sizeof(t));
if (t.tno == IdToSearchFor)
{
found = 1;
cout << "\nNo. of Passengers: " << t.nop;
cout << "\nTrain Name: " << t.tname;
cout << "\nDesitnation: " << t.dest;
cout << "\nDistance: " << t.dist;
cout << "\nFare: " << t.fare;
cout << "\n\n";
cout << "Do you want to Modify the above record[Y/N]:";
ModifyYesNo = GetYN();
if (ModifyYesNo == 'y' || ModifyYesNo == 'Y')
{
DataFileo.open("Train.dat", ios::binary | ios::out | ios::in)
cout << "Do you want to modify the train name[y/n]";
ModifyYesNo = GetYN();
if (ModifyYesNo == 'y' || ModifyYesNo == 'Y')
{
cout << "\nEnter the name of the train: ";
gets(t.tname);
}
cout << "Do you want to modify the Destination[y/n]";
ModifyYesNo = GetYN();
if (ModifyYesNo == 'y' || ModifyYesNo == 'Y')
{
cout << "\nEnter new destination: ";
gets(t.dest);
}
cout << "Do you want to modify the Distance[y/n]";
ModifyYesNo = GetYN();
if (ModifyYesNo == 'y' || ModifyYesNo == 'Y')
{
cout << "\nEnter the new distance: ";
cin >> t.dist;
}
cout << "Do you want to modify the Fare[y/n]";
ModifyYesNo = GetYN();
if (ModifyYesNo == 'y' || ModifyYesNo == 'Y')
{
cout << "\nEnter the new fare: ";
cin >> t.fare;
}
DataFileo.write((char*)&t, sizeof(t));
break;
}
}
} while (!DataFilei.eof());
if (found == 0)
{
cout << "\nRecord not found!";
DataFilei.close();
DataFileo.close();
cout << "\nPress any key to continue.";
getch();
}
}
void Rail::AddRecord()
{
fstream DataFile;
DataFile.open("Train.dat", ios::app | ios::binary);
char ContinueYN = 'N';
do
{
clrscr()
cout << "\nEnter the train number: ";
cin >> t.tno;
cout << "\nEnter the no of pasengers: ";
cin >> t.nop;
cout << "\nEnter the train name: ";
gets(t.tname);
cout << "\nEnter the destination: ";
gets(t.dest);
cout << "\nEnter the distance: ";
cin >> t.dist;
cout << "\nEnter the fare: ";
cin >> t.fare;
DataFile.write((char*)&t, sizeof(t));
cout << "\nDo you want to enter another record[y/n]";
ContinueYN = GetYN();
system("cls");
} while (ContinueYN == 'Y' || ContinueYN == 'y')
DataFile.close();
}
void Rail::Delete()
{
fstream DataFilei;
fstream DataFileo;
int IdToSearchFor, found = 0;
char ModifyYesNo;
clrscr()
cout << "\nEnter the train no of the record to delete: ";
cin >> IdToSearchFor;
DataFilei.open("Train.dat", ios::binary | ios::in);
DataFile.read((char*)&t, sizeof(t));
while (!DataFilei.eof())
{
if (t.tno == IdToSearchFor)
{
cout << "\nNo. of Passengers: " << t.nop;
cout << "\nTrain name: " << t.tname;
cout << "\nDestination: " << t.dest;
cout << "\nDistance: " << t.dist;
cout << "\nFare: " << t.fare;
cout << "\n\n";
cout << "Do you want to Delete the above record[y/n]:";
ModifyYesNo = GetYN();
found = 1;
}
DataFilei.read((char*)&t, sizeof(t));
}
if (found == 0)
{
cout << "Record not found!";
cout << "\nPress any key to continue.";
getch();
}
DataFilei.close();
if (ModifyYesNo == 'Y' || ModifyYesNo == 'y')
{
DataFilei.open("Train.dat", ios::binary | ios::in);
DataFileo.open("Temp.dat", ios::binary | ios::out);
DataFilei.read((char*)&t, sizeof(t));
while (!DataFile.eof())
{
if (t.tno != IdToSearchFor)
DataFileo.write((char*)&t, sizeof(t));
DataFilei.read((char*)&t, sizeof(t));
}
DataFileo.close();
DataFilei.close();
DataFileo.open("Temp.dat", ios::binary | ios::in);
DataFilei.open("Train.dat", ios::binary | ios::out);
while (!DataFile.eof())
{
DataFileo.write((char*)&t, sizeof(t));
DataFilei.read((char*)&t, sizeof(t));
}
DataFileo.close();
DataFilei.close();
}
}
void main()
{
introduction();
clrscr()
int choice;
do
{
system("cls");
cout << "\tMain Menu\n";
cout << "\t1. Create a new Flight file\n";
cout << "\t2. Display Flight record\n";
cout << "\t3. Search in Flight record\n";
cout << "\t4. Add record\n";
cout << "\t5. Delete record\n";
cout << "\t6. Modify record\n";
cout << "\t7. Exit\n\n";
cout << "Enter your choice";
cin >> choice;
switch (choice)
{
case 1:R.CreateFile();
break;
case 2:R.Display();
break;
case 3:R.Search();
break;
case 4:R.AddRecord();
break;
case 5:R.Delete();
break;
case 6:R.Modify();
break;
}
} while (choice != 7);
}
此代码是用turbo c ++ 4.5编写的。
它出了什么问题?
答案 0 :(得分:7)
第27/28行是
void introduction();
{
删除;
并删除TurboC ++。
TurboC ++ 4.5是从大约1993年开始的(C ++在1998年之前甚至没有标准化 最近(2011+)又出现了很大的变化。帮自己一个忙,切换 GCC或Clang,或者(如果你不需要很多新功能)VS.
如果我说这段代码产生近~370行,也许会有所帮助
错误(纠正包含后,因为它不会编译
其他任何东西)。最新的G ++与-std = c ++ 1y,Wall和Wextra