473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Deleting records

How do I delete records? Ive written a program that can add new records
and I can display what I've entered, but how do I select certain
records to delete?

Code below

#include <cstdlib>
#include <iostream>

using namespace std;

struct Boat
{
char BoatOwn [50];
char BoatName[50] ;
int TypeBoat;
int LengthBoat;
int DepthBoat;
Boat* next;
};

int main(int argc, char *argv[])
{
int menuOption; //stores the users entered menu choice

int LengthBoatTemp; //stores the boat length in metres
int DepthBoatTemp; //stores the boat depth in metres

int duration; //stores the duration in months
int rate;
char confirm; //Yes or No confirmation
int spaceUsed=0; //Space in marina

//stockStruct pointers don't point anywhere at moment
Boat* head = NULL;
Boat* current = NULL;
Boat* last = NULL;
Boat* currentTemp = NULL; //This is used to display records

while (menuOption!=4)
{

//The 4 option choices
cout << "\t\t\t\t1. Add New Booking." << endl;
cout << "\t\t\t\t2. Delete a Record." << endl;
cout << "\t\t\t\t3. Display all Booking Records." <<
endl;
cout << "\t\t\t\t4. Exit Program." << endl;
cout << "" << endl;
cout << "" << endl;
cout<<"\n";
cout<<"\t\t\t\tPlease select an option: ";
cin>>menuOption;

if (menuOption==1)
{
system ("CLS");
cout<<"\n\n\t\tBoat length: ";
cin>>LengthBoatTemp;
//If the boat is too big an error message appears
if (LengthBoatTemp>15)
{
cout<<"\t\tYour boat is too long for the marina!" <<
endl;
system("PAUSE");
system("CLS");
}
else
{
//checks to see if there is enough space in marina
currentTemp=head;
spaceUsed=0;

while (NULL!=currentTemp)
{
spaceUsed=spaceUsed+currentTemp->LengthBoat;
currentTemp=currentTemp->next;
}

if (150<(LengthBoatTemp+spaceUsed))
{
cout<<"\t\tThe Marina is full, sorry booking must
be cancelled" << endl;
system("PAUSE");
system("CLS");
}
else
{
cout<<"\t\tBoat Depth: "<<endl;
cin >DepthBoatTemp;
if (DepthBoatTemp>5)
{
cout<<"The boat exceeds the maximum depth, we
can't complete the booking\n";
system("PAUSE");
system("CLS");
}

else
{
cout<<"\t\tEnter the length of your stay
(months): ";
cin>>duration;
rate=(10*LengthBoatTemp)*duration;
cout << "\n";
cout <<"\t\tTotal cost: " << rate << endl;
cout <<"\n";
cout <<"\t\t\tProceed with the booking? (y/n)
";
cin >confirm;
system ("CLS");
if (confirm=='y'||confirm=='Y')

{
last=current;
current = new Boat;
cout << "\t\tEnter Owners Name: ";
cin>>current->BoatOwn;

cout<<"\t\tEnter Boat Name: ";
cin>>current->BoatName;

cout<<"\t\tWhat type of Boat?:" << endl;
cout << "\t\t\t1. Motor " << endl;
cout << "\t\t\t2. Sailing " << endl;
cout << "\t\t\t3. Narrow\n\n\t\t\t";
cout << "Choice ";
cin >current->TypeBoat;
current->LengthBoat=LengthBoatTemp;
current->DepthBoat=DepthBoatTemp;
current->next=NULL;

if (NULL==head)
{
head=current; //make current pointer the
head
}

if (NULL!=last)
{
last->next = current; //make last point
at the new record
}
cout << "\n";
cout<<"\t\tYour booking has been
entered\n";
system("PAUSE");
system("CLS");
}
else
{
cout<<"Your booking couldn't be
completed\n"<<endl;

} //end of y or N
} //end of else boat depth
}//end of else marina length
} //end of else boat length
} //end of option1

else if (menuOption==2)
{

}
else if (menuOption==3)
{

currentTemp=head;
spaceUsed=0;

while (NULL!=currentTemp)
{
cout << "Owner of Boat : " <<
currentTemp->BoatOwn << endl;
cout << "Name of Boat : " <<
currentTemp->BoatName << endl;
cout << "Type of boat: " << currentTemp->TypeBoat
<< endl;
cout << "Length of Boat: " <<
currentTemp->LengthBoat <<" metres" << endl;
cout << "Depth of the Boat : " <<
currentTemp->DepthBoat << " metres" << endl;
cout << "\n";
spaceUsed=spaceUsed+currentTemp->LengthBoat;
currentTemp=currentTemp->next;
}

cout<<"Available Space left in the marina: " <<
(150-spaceUsed)<<" metres\n\n";
system("PAUSE");
system("CLS");
/* char buffer[180];
char lineName[20];
long shotPoint, x, y;
// Open the file
FILE *fp;

if ( (fp = fopen("marina.csv", "r")) == NULL )
{
cout << "Unable to open file program aborting"<<endl;
system("PAUSE");
return(-1);
}

while (!feof(fp))
{
fgets( buffer, 179, fp);
cout << "buffer = " << buffer << "\n";
// sscanf( buffer, "%16s%5ld%8ld%8ld", lineName, &shotPoint, &x, &y
);
// cout << "Owner = " << lineName << "\n";
// cout << "Boat Name = " << shotPoint << "\n";
// cout << "Length = " << x << "\n";
// cout << "Depth = " << y << "\n\n";
}

fclose(fp); */

}//end of option 3

else if (menuOption==4)
{
cout << "Exiting " << endl;
system("PAUSE");
return EXIT_SUCCESS;
}}}

Dec 7 '06 #1
3 2989

Daz01 wrote:
< sniped irrelevant code >

#include <list>

struct Boat
{
bool operator == (Boat const & b) const;
};

std::list<Boatboats;

Boat b;

// to add to the list
boats.push_back(b);

// to remove from the list
boats.remove(b);

appart from iostreams I can't see anything other than C code.
this is a C++ group

Also, post minimal code that ilustrates your problem.

Dec 7 '06 #2
On Thu, 07 Dec 2006 07:32:21 -0800, Daz01 wrote:
How do I delete records? Ive written a program that can add new records
and I can display what I've entered, but how do I select certain
records to delete?

Code below

#include <cstdlib>
#include <iostream>

using namespace std;

struct Boat
{
char BoatOwn [50];
char BoatName[50] ;
int TypeBoat;
int LengthBoat;
int DepthBoat;
Boat* next;
};

[snip more code]
You appear to be attempting to design and implement your own (singly)
linked list. I suspect you are thus re-inventing a (probably rather
wobbly) wheel ;) I would strongly suggest that you don't attempt this - it
is difficult and very error-prone to design even a reasonably simple list
class - but rather use the standard C++ list, which implements all the
functionality you require (adding, deleting and referencing "records").

You'll find the standard list class template in the header file <list>. The
standard C++ container class templates take a bit of getting used to but it
is *very* worthwhile to do so - any time put into learning to use them
will be offset against the considerable effort of debugging your own
efforts. And it also makes your code far more maintainable and
comprehensible to others.

Good luck,

--
Lionel B
Dec 7 '06 #3

Daz01 wrote:
How do I delete records? Ive written a program that can add new records
and I can display what I've entered, but how do I select certain
records to delete?

Code below
Learn how to use a std::list, your program will take 10 minutes to
write instead of a month.

#include <list>

Record {
...
};

int main()
{
std::list< Record records;
}

If you really, really want to reinvent the wheel, design a simple
node-based templated list. The node struct should be an embedded
struct. That way you can later pass any user-type as T. When you design
a container of any kind, make it work with a plain primitive integer
first. That alone still presents a challenge since managing pointers is
not guesswork and absolutely critical.

template< typename T >
class MyList
{
struct node_t
{
T t;
node_t(const T& t, node_t* p)
: p_prev(p), p_next(0) { }
node_t* p_prev;
node_t* p_next;
} *p_head, *p_tail;

MyList() : p_head(0), p_tail(0) { }
... and so on
};

Note, all members are initialized via constructors. Without exceptions.
If you break that rule, you'll fail.

Dec 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
2
by: uv | last post by:
Hi! I'm having problems submitting a new record through the form. I'm working with the wizard and I've added a control button to my form for entering entering a new record but for some reason it...
3
by: Mike Turco | last post by:
I'm working on an application that imports and exports tons of CSV data, like 64,000 records per file, and six or seven files in a set. First off, by the tine I import a few hundred thousand...
1
by: Coy Howe | last post by:
This one seems bizarre! We have a database consisting of a main table and 12 - 15 "sub" tables, which are connected via cascading relationships. The database performs many complex calculations...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
2
by: azmiza | last post by:
Hi everybody, I need your help. I want to view my sql database and its work very well which is display in my web browser but once I want to press button yes, its not working, I check the...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
2
by: padmaneha | last post by:
Hi I have created two tables 'TrainsMaster' & 'TransArrvlDepinfo' Columns which I have created in 'TrainsMaster' are 'trainName,TrainNo, StartStaionId, & EndstationId' Columns which I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.