D
Daz01
Hi, Ive written a program. But I want to add a class in it somehow? Is
there any easy way to do it.
Below is the code for the program:
#include <cstdlib>
#include <iostream>
using namespace std;
struct Boat
{
char BoatOwn[50];
char BoatNme[50];
int TypeBoat;
int LengthBoat;
int DepthBoat;
Boat* next;
};
int main()
{
int menuOption;
int LengthBoatTemp;
int DepthBoatTemp;
int duration;
int rate;
char confirm;
int spaceUsed=0;
//Pointers don't point to any destination at the moment
Boat* head = NULL;
Boat* current =NULL;
Boat* last = NULL;
Boat* currentTemp= NULL;
while (menuOption!=4)
{
//User options
cout << "\n\n1: New Booking" <<endl;
cout << "\n\n2: Delete Record" <<endl;
cout << "\n\n3: Display all Records" <<endl;
cout << "\n\n4: Exit" <<endl;
cout << "\n\n\nPlease select an option: ";
cin >> menuOption;
if (menuOption ==1)
{
system ("CLS");
cout << "\t\t\t" <<endl;
cout << "Please enter boat details:" <<endl;
cout << "Boat length:" <<endl;
cin >> LengthBoatTemp;
if (LengthBoatTemp >15)
{
cout << "\n\n Your boat is too big to fit into the marina,
sorry:" <<endl;
}
else
{
//check if there is any space in the marina
currentTemp= head;
spaceUsed=0;
while (NULL!=currentTemp)
{
spaceUsed=spaceUsed+currentTemp->LengthBoat;
currentTemp=currentTemp->next;
}
if (150<(LengthBoatTemp+spaceUsed))
{
cout << "\n\nThe marina is full, sorry:" <<endl;
}
else
{
cout << "\n\nDepth of Boat: ";
cin >> DepthBoatTemp;
if (DepthBoatTemp > 5)
{
cout << "Your boat is too deep for the marina, it exceeds the
max depth:" <<endl;
}
else
{
cout <<"\n\nPlease enter the length of your stay in months:"
<<endl;
cin >> duration;
rate= (10*LengthBoatTemp)*duration;
cout << "\n" <<endl;
cout << "\n\nTotal cost:" << rate <<endl;
cout << "\n" <<endl;
cout<< "\n\nDo you want to proceed with the booking? (Y/N)"
<<endl;
cin >>confirm;
if (confirm=='Y'||confirm=='Y')
{
last=current;
current = new Boat;
cout <<"\n\n\n:" <<endl;
cout << "\n\nPlease enter Owner and Boat details into the
system:" <<endl;
cout << "Enter Owners Name:" <<endl;
cin >> current->BoatOwn;
cout << "Enter the Boats Name:" <<endl;
cin >> current->BoatNme;
cout << "Enter what type of boat it is:" <<endl;
cout << " Motor, Sailing or Narrow:" <<endl;
cout << "Choice";
cin >> current->TypeBoat;
current->LengthBoat=LengthBoatTemp;
current->DepthBoat=DepthBoatTemp;
current->next=NULL;
if (NULL==head)
{
head=current;
}
if (NULL!=last)
{
last->next = current;
}
cout << "\n";
cout <<"\n\nBooking completed successfully:" <<endl;
}
else
{
cout <<"Your booking couldn't be completed:";
} //this is the end of Y/N
} //this is the end of else Depth of Boat
} //this is the end of else Marina Length
} //this is the end of Length of Boat
} // this is the end of Option1
else if (menuOption==2)
{
}
else if (menuOption==3)
{
cout << "Boats already in marina:"<<endl;
currentTemp=head;
spaceUsed=0;
while (NULL!=currentTemp)
{
cout << "Owners Name:" <<
currentTemp->BoatOwn <<endl;
cout << "Boat Name:" <<
currentTemp->BoatNme <<endl;
cout << "Type of Boat:" <<
currentTemp->TypeBoat <<endl;
cout << "Length of Boat:" <<
currentTemp->LengthBoat << "meteres" <<endl;
cout << "Depth of Boat:" <<
currentTemp->DepthBoat << "meteres" <<endl;
spaceUsed=spaceUsed+currentTemp->LengthBoat;
currentTemp=currentTemp->next;
}
cout<<"Available Space: " << (500-spaceUsed)<<"
metres\n\n:" <<endl;
system("PAUSE");
system("CLS");
//* char buffer[180];
char lineName[20];
long shotPoint, x, y;
}
system("PAUSE");
return EXIT_SUCCESS;
}
}
there any easy way to do it.
Below is the code for the program:
#include <cstdlib>
#include <iostream>
using namespace std;
struct Boat
{
char BoatOwn[50];
char BoatNme[50];
int TypeBoat;
int LengthBoat;
int DepthBoat;
Boat* next;
};
int main()
{
int menuOption;
int LengthBoatTemp;
int DepthBoatTemp;
int duration;
int rate;
char confirm;
int spaceUsed=0;
//Pointers don't point to any destination at the moment
Boat* head = NULL;
Boat* current =NULL;
Boat* last = NULL;
Boat* currentTemp= NULL;
while (menuOption!=4)
{
//User options
cout << "\n\n1: New Booking" <<endl;
cout << "\n\n2: Delete Record" <<endl;
cout << "\n\n3: Display all Records" <<endl;
cout << "\n\n4: Exit" <<endl;
cout << "\n\n\nPlease select an option: ";
cin >> menuOption;
if (menuOption ==1)
{
system ("CLS");
cout << "\t\t\t" <<endl;
cout << "Please enter boat details:" <<endl;
cout << "Boat length:" <<endl;
cin >> LengthBoatTemp;
if (LengthBoatTemp >15)
{
cout << "\n\n Your boat is too big to fit into the marina,
sorry:" <<endl;
}
else
{
//check if there is any space in the marina
currentTemp= head;
spaceUsed=0;
while (NULL!=currentTemp)
{
spaceUsed=spaceUsed+currentTemp->LengthBoat;
currentTemp=currentTemp->next;
}
if (150<(LengthBoatTemp+spaceUsed))
{
cout << "\n\nThe marina is full, sorry:" <<endl;
}
else
{
cout << "\n\nDepth of Boat: ";
cin >> DepthBoatTemp;
if (DepthBoatTemp > 5)
{
cout << "Your boat is too deep for the marina, it exceeds the
max depth:" <<endl;
}
else
{
cout <<"\n\nPlease enter the length of your stay in months:"
<<endl;
cin >> duration;
rate= (10*LengthBoatTemp)*duration;
cout << "\n" <<endl;
cout << "\n\nTotal cost:" << rate <<endl;
cout << "\n" <<endl;
cout<< "\n\nDo you want to proceed with the booking? (Y/N)"
<<endl;
cin >>confirm;
if (confirm=='Y'||confirm=='Y')
{
last=current;
current = new Boat;
cout <<"\n\n\n:" <<endl;
cout << "\n\nPlease enter Owner and Boat details into the
system:" <<endl;
cout << "Enter Owners Name:" <<endl;
cin >> current->BoatOwn;
cout << "Enter the Boats Name:" <<endl;
cin >> current->BoatNme;
cout << "Enter what type of boat it is:" <<endl;
cout << " Motor, Sailing or Narrow:" <<endl;
cout << "Choice";
cin >> current->TypeBoat;
current->LengthBoat=LengthBoatTemp;
current->DepthBoat=DepthBoatTemp;
current->next=NULL;
if (NULL==head)
{
head=current;
}
if (NULL!=last)
{
last->next = current;
}
cout << "\n";
cout <<"\n\nBooking completed successfully:" <<endl;
}
else
{
cout <<"Your booking couldn't be completed:";
} //this is the end of Y/N
} //this is the end of else Depth of Boat
} //this is the end of else Marina Length
} //this is the end of Length of Boat
} // this is the end of Option1
else if (menuOption==2)
{
}
else if (menuOption==3)
{
cout << "Boats already in marina:"<<endl;
currentTemp=head;
spaceUsed=0;
while (NULL!=currentTemp)
{
cout << "Owners Name:" <<
currentTemp->BoatOwn <<endl;
cout << "Boat Name:" <<
currentTemp->BoatNme <<endl;
cout << "Type of Boat:" <<
currentTemp->TypeBoat <<endl;
cout << "Length of Boat:" <<
currentTemp->LengthBoat << "meteres" <<endl;
cout << "Depth of Boat:" <<
currentTemp->DepthBoat << "meteres" <<endl;
spaceUsed=spaceUsed+currentTemp->LengthBoat;
currentTemp=currentTemp->next;
}
cout<<"Available Space: " << (500-spaceUsed)<<"
metres\n\n:" <<endl;
system("PAUSE");
system("CLS");
//* char buffer[180];
char lineName[20];
long shotPoint, x, y;
}
system("PAUSE");
return EXIT_SUCCESS;
}
}