PDA

View Full Version : Convert CPP to Standard C


diasmj
08-04-2006, 03:11 PM
Just wondering if it was possbile to convert CPP to Standard C???

Here is the code:

#include "ptoc.h"



/*#include "WinCrt.h"*/
/*#include "Strings.h"*/



const char custfile[] = "c:\\airlinecustomer.txt";
const char seatfile[] = "c:\\seat.txt";
const integer Max_num_cust = 50;
const integer maxseat = 100;

struct customertype {
varying_string<5> Title;
varying_string<15> First_Name;
varying_string<15> Surname;
varying_string<10> DOB;
varying_string<25> Address_1;
varying_string<30> Address_2;
varying_string<15> Address_3;
varying_string<7> Postcode;
string Passport;
varying_string<10> Telephone;
string Prefsm;
varying_string<3> Prefve;

};

char Choice;
char another;
array<1,Max_num_cust,customertype> cust;
array<1,maxseat,seattype> Seat;
file<seattype> seatdata;
seattype seattemp;
customertype custtemp;
file<customertype> data;
integer custcount;
integer reccount;
boolean found;
integer foundpos;
integer seat_pos;
integer loadcount;


void Delay()


{
integer count1;
integer count2;


for( count1=1; count1 <= 2000; count1 ++)
{
for( count2=1; count2 <= 30000; count2 ++);
}
}



void AddCustomers()

{
integer storecount;
integer lengthcode;
string passporttemp;


reccount=1;

do {

output << "You Chose to Add a New Customer" << NL;
output << "" << NL;
output << "Enter Title" << NL;
input >> cust[reccount].Title >> NL;
output << "Enter First Name" << NL;
input >> cust[reccount].First_Name >> NL;
output << "Enter Surname" << NL;
input >> cust[reccount].Surname >> NL;
output << "Enter Date of Birth" << NL;
output << "PLEASE USE ONLY THIS FORMAT (DD/MM/YYYY)" << NL;
input >> cust[reccount].DOB >> NL;
output << "Enter Address Line 1" << NL;
input >> cust[reccount].Address_1 >> NL;
output << "Enter Address Line 2" << NL;
input >> cust[reccount].Address_2 >> NL;
output << "Enter Address Line 3" << NL;
input >> cust[reccount].Address_3 >> NL;
output << "Enter Postcode" << NL;
input >> cust[reccount].Postcode >> NL;
do {
output << "Enter Passport No." << NL;
input >> cust[reccount].Passport >> NL;
passporttemp=cust[reccount].Passport;
lengthcode= length(passporttemp);
if (lengthcode != 6) output << "Error!!! Code must be 6 digits " << lengthcode << NL; } while (!(lengthcode == 6));
output << "Enter Contact Number" << NL;
input >> cust[reccount].Telephone >> NL;
output << "Enter Prefrences Smoking/NonSmoking" << NL;
input >> cust[reccount].Prefsm >> NL;
output << "Are you a Vegetarian" << NL;
input >> cust[reccount].Prefve >> NL;
output << "Do you Want to Add Another\? (Y)es/(N)o" << NL;
input >> another >> NL;

if (another =='y')
reccount =reccount +1;
clrscr;

} while (!((another == 'n') || (reccount == Max_num_cust)));
assign (data, custfile);
reset (data);
seek(data,filesize(data));
for( storecount = 1; storecount <= reccount; storecount ++)
data << cust[storecount];
close (data); /*close the file*/
output << "Updating Customer.dat." << NL;
Delay();
clrscr;
output << "Updating Customer.dat.." << NL;
Delay();
clrscr;
output << "Updating Customer.dat..." << NL;
Delay();
clrscr;
output << "Done" << NL;
Delay();
clrscr;

}


void readfile()

{
assign (data, custfile);
reset(data);
loadcount=1;
while (! eof (data))
{
data >> cust[loadcount];
loadcount=loadcount + 1;
}
close(data);
}


void Sort()
/*Variables*/
{
boolean Flag;
integer num;
integer count;
integer loopcount;
integer max;


assign(data, custfile);
reset(data);
seek(data,filesize(data));
num=filesize(data);
loopcount=1;
max=Max_num_cust;
Flag = false;

do {

for( max = num; max >= 0; max --)
{
for( count =0; count <= num-1; count ++)
{
if (cust[count].Surname > cust[count+1].Surname) /
{
custtemp = cust[count];
cust[count] = cust[count+1]; cust[count+1] = custtemp;
Flag = true;
}
}
}


num=num-1;


for( loopcount=1; loopcount <= num+1; loopcount ++)



{
output << "Record No:" << loopcount << NL;
output << NL;
output << "Title : " << cust[loopcount].Title << NL;

output << "First Name : " << cust[loopcount].First_Name << NL;
output << "Surname : " << cust[loopcount].Surname << NL;
output << "Date of Birth : " << cust[loopcount].DOB << NL;
output << NL;
output << "Address Line 1 : " << cust[loopcount].Address_1 << NL;
output << "Address Line 2 : " << cust[loopcount].Address_2 << NL;
output << "Address Line 3 : " << cust[loopcount].Address_3 << NL;
output << "PostCode : " << cust[loopcount].Postcode << NL;
output << "Phone Number : " << cust[loopcount].Telephone << NL;
output << NL;
output << "Passport No : " << cust[loopcount].Passport << NL;
output << NL;
output << "Smoking or Nonsmoking : " << cust[loopcount].Prefsm << NL;
output << "Vegetarian : " << cust[loopcount].Prefve << NL;
output << "---------------------------------------------" << NL;
output << "Press Enter to go to Next Record" << NL;
input >> NL;
clrscr;

}


} while (!(count==num));

close(data);


}

void load_data()


{
string answer;
integer loopcount;


output << "Do you want to sort records in Alphabetical order? Y or N" << NL;
input >> answer >> NL;
clrscr;
if (answer=='y')
Sort();
else if (answer=='n')
{
assign (data, custfile);
reset(data);
loadcount=1;
while (! eof (data))
{
data >> cust[loadcount];
loadcount=loadcount + 1;
}
close(data);
for( loopcount=1; loopcount <= (loadcount-1); loopcount ++)
{
output << "Record No:" << loopcount << NL;
output << "" << NL;
output << "Title : " << cust[loopcount].Title << NL;
output << "First Name : " << cust[loopcount].First_Name << NL;
output << "Surname : " << cust[loopcount].Surname << NL;
output << "Date of Birth : " << cust[loopcount].DOB << NL;
output << "" << NL;
output << "Address Line 1 : " << cust[loopcount].Address_1 << NL;
output << "Address Line 2 : " << cust[loopcount].Address_2 << NL;
output << "Address Line 3 : " << cust[loopcount].Address_3 << NL;
output << "PostCode : " << cust[loopcount].Postcode << NL;
output << "Phone Number : " << cust[loopcount].Telephone << NL;
output << "" << NL;
output << "Passport No : " << cust[loopcount].Passport << NL;
output << "" << NL;
output << "Smoking or Nonsmoking : " << cust[loopcount].Prefsm << NL;
output << "Vegetarian : " << cust[loopcount].Prefve << NL;
output << "---------------------------------------------" << NL;
output << "Press Enter to go to Next Record" << NL;
input >> NL;
clrscr;
}
output << "Press Enter to go Back" << NL;
input >> NL;
clrscr;
}
}

void EditCustomer()


{
string Choice;
integer lengthcode;
string passporttemp;


output << "You Chose to Edit a Customer" << NL;
output << "" << NL;
output << "Record No. " << foundpos+1 << " Surname: " << custtemp.Surname << NL;
assign(data, custfile);
reset(data);
seek(data, foundpos);
data >> custtemp;
do {
output << "Which Field to you wish to edit?" << NL;
output << NL;
output << "(T)itle : " << custtemp.Title << NL;
output << "(F)irst Name : " << custtemp.First_Name << NL;
output << "(S)urname : " << custtemp.Surname << NL;
output << "(D)ate of Birth: " << custtemp.DOB << NL;
output << NL;
output << "Address Line (1): " << custtemp.Address_1 << NL;
output << "Address Line (2): " << custtemp.Address_2 << NL;
output << "Address Line (3): " << custtemp.Address_3 << NL;
output << "(P)ostCode: " << custtemp.Postcode << NL;
output << "(C)ontact Number: " << custtemp.Telephone << NL;
output << NL;
output << "Passp(o)rt No: " << custtemp.Passport << NL;
output << NL;
output << "Prefere(n)ces: " << custtemp.Prefsm << NL;
output << "(V)egiterian: " << custtemp.Prefve << NL;
output << "(E)xit" << NL;
input >> Choice >> NL;

if ((Choice=='t') || (Choice=='T'))
{
output << "Enter New Title" << NL;
input >> custtemp.Title >> NL;
}

else if ((Choice=='f') || (Choice=='F'))
{
output << "Enter New First Name" << NL;
input >> custtemp.First_Name >> NL;
}

else if ((Choice=='s') || (Choice=='S'))
{
output << "Enter New Surname" << NL;
input >> custtemp.Surname >> NL;
}

else if ((Choice=='d') || (Choice=='D'))
{
output << "Enter New Date of Birth" << NL;
output << "PLEASE USE ONLY THIS FORMAT (DD/MM/YYYY)" << NL;
input >> custtemp.DOB >> NL;
}

else if (Choice=='1')
{
output << "Enter New Address Line 1" << NL;
input >> custtemp.Address_1 >> NL;
}

else if (Choice=='2')
{
output << "Enter New Address Line 2" << NL;
input >> custtemp.Address_2 >> NL;
}

else if (Choice=='3')
{
output << "Enter New Address Line 3" << NL;
input >> custtemp.Address_3 >> NL;
}

else if ((Choice=='p') || (Choice=='P'))
{
output << "Enter New Postcode" << NL;
input >> custtemp.Postcode >> NL;
}

else if ((Choice=='o') || (Choice=='O'))
{
do {
output << "Enter New Passport No." << NL;
input >> custtemp.Passport >> NL;
passporttemp=custtemp.Passport;
lengthcode= length(passporttemp);
if (lengthcode != 6)
output << "Error!!! Code must be 6 digits " << lengthcode << NL;
} while (!(lengthcode == 6));
}

else if ((Choice=='c') || (Choice=='C'))
{
output << "Enter New Contact Number" << NL;
input >> custtemp.Telephone >> NL;
}

else if ((Choice=='n') || (Choice=='N'))
{
output << "Enter New Prefrences Smoking/NonSmoking" << NL;
input >> custtemp.Prefsm >> NL;
}

else if ((Choice=='v') || (Choice=='V'))
{
output << "Are You a Vegetarian" << NL;
input >> custtemp.Prefve >> NL;
}

Clrscr;
} while (!((Choice=='e') || (Choice=='E')));
seek(data,foundpos);
data << custtemp;
close(data);
output << "Updating Customer.dat." << NL;
Delay();
clrscr;
output << "Updating Customer.dat.." << NL;
Delay();
clrscr;
output << "Updating Customer.dat..." << NL;
Delay();
clrscr;
output << "Updated" << NL;
Delay();
clrscr;
}


void DeleteCustomer()

{
string answer;


output << "Are you sure you want to Delete " << custtemp.Title << ' ' << custtemp.Surname << NL;
input >> answer >> NL;
if (answer=='y')
{
assign(data,custfile);
reset(data);
seek(data,filesize(data)-1);
data >> custtemp;
seek(data,foundpos);
data << custtemp;
seek(data,filesize(data)-1);
truncate(data);
close(data);
Clrscr;
output << "Deleting Customer Record." << NL;
Delay();
clrscr;
output << "Deleting Customer Record.." << NL;
Delay();
clrscr;
output << "Deleting Customer Record..." << NL;
Delay();
clrscr;
output << "Deleted Record" << NL;
Delay();
clrscr;
output << "Press Enter to go Back" << NL;
input >> NL;
clrscr;
}

else if (answer=='n')
{
output << "Record for " << custtemp.Title << ' ' << custtemp.Surname << " was not deleted" << NL;
input >> NL;
Clrscr;
}

else
{
output << "Invaild Answer" << NL;
DeleteCustomer();
}
}



void Searchsurname()

{
string Searchname;
integer counter;
boolean found;
integer sizehold;

assign (data, custfile);

reset(data);

sizehold = filesize(data);

if (sizehold != 0) /

{
output << "Enter Surname you wish to Find, Case Sensitive!!" << NL;
input >> Searchname >> NL;
do {
seek(data,counter); /*searches the file*/
data >> custtemp;
found= (custtemp.Surname == Searchname); /*this compares the searched name to the name in the file*/

if (found)

foundpos=counter;

counter=counter+1;


} while (!(found || eof(data)));

if (found)
{
seek(data,foundpos);
data >> custtemp;
output << "Record Found!!!" << NL;
output << "" << NL;
output << "RECORD NO: " << foundpos+1 << NL;
output << "Title : " << custtemp.Title << " First Name: "
<< custtemp.First_Name << " Surname: " << custtemp.Surname << NL;
output << "Date of Birth: " << custtemp.DOB << NL;
output << "Address Line 1: " << custtemp.Address_1 << NL;
output << "Address Line 2: " << custtemp.Address_2 << NL;
output << "Address Line 3: " << custtemp.Address_3 << NL;
output << "PostCode: " << custtemp.Postcode << NL;
output << "Phone Number: " << custtemp.Telephone << NL;
output << "Passport No: " << custtemp.Passport << NL;
output << "Preferences: " << custtemp.Prefsm << NL;
output << "Vegetarian: " << custtemp.Prefve << NL;
output << "---------------------------------------------" << NL;
output << " *********************" << NL;
output << " * *" << NL; /*Gives the user options*/
output << " * (E)dit Customer *" << NL;
output << " * (D)elete Customer *" << NL;
output << " * *" << NL;
output << " * E(x)it *" << NL;
output << " * *" << NL;
output << " *********************" << NL;
input >> Choice >> NL;
Clrscr;
close(data);
}

else
{
Clrscr;
output << "You Searched " << Searchname << NL; /*if surname not found then this message appears*/
output << "Not Found, Please try again!!" << NL;
Searchsurname();
}
if (Choice == 'e')
EditCustomer();
else if (Choice== 'd')
DeleteCustomer();

}

else
{
output << "There are no records to search" << NL;
input >> NL;
clrscr;
}
}

void menu()

{
StrCopy (WindowTitle, "Airline Booking System"); /*Message on title bar During program*/
StrCopy (InactiveTitle, "Made By Mark Dias 2002"); /*Message on title bar when the program is finished*/

output << "Welcome to Airline Booking System" << NL;
output << "Made by Mark Dias" << NL;
output << "" << NL;
output << " ************ Main Menu *************" << NL; /*options*/
output << " * *" << NL;
output << " * Press A - (A)dd a Customer *" << NL;
output << " * Press V - (V)iew All Customers *" << NL;
output << " * *" << NL;
output << " * Press S - (S)earch *" << NL;
output << " * *" << NL;
output << " * Press C - (C)ancel Flight *" << NL;
output << " * Press Q - (Q)uit *" << NL;
output << " * *" << NL;
output << " ************************************" << NL;
input >> Choice >> NL;
clrscr;

switch (Choice) {

case 'A':case 'a': AddCustomers(); break; /*Calls in the add customers procedure*/
case 'V':case 'v': load_data(); break; /*Calls in the view customers procedure*/
case 'S':case 's': Search(); break; /*Calls in the search menu procedure*/
case 'C':case 'c': CancelFlight(); break; /*Calls in the reset seats procedure*/
case 'Q':case 'q': output << "Thank You for Using The Airline Booking System" << NL; break; /*Quit message*/

default:
output << "" << NL;
output << "Invalid Option" << NL;

}
}

/*----------------------------------Main Program-----------------------------
This is where the main menu is called from.*/
int main(int argc, const char* argv[])
{
pio_initialize(argc, argv);
do {
readfile(); /*Calls in the readfile procedure*/
menu(); /*calls in the main menu procedure*/
} while (!(Choice == 'q'));
return EXIT_SUCCESS;
}

Is this can be done, i will owe u so much :thumbsup:

rpgfan3233
08-04-2006, 09:16 PM
I have a question. In varying_string<N>, what does N represent? The number of strings (e.g. an array of strings) or the length of a single string?