473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What'ch think of my program? *fixed word wrap*

/* This program is a database program that will store
video tape names, minutes, year released, and price
I want it to be professional so that *YOU* will want
to buy it and use it for a video store, j/k about that
but i want it to be professional */
// note to leor, display works fine, you must have
// pressed update
#include<iostre am>
#include<string >
using namespace std;

int totalnodes= 0; // the nodes in this case are tapes
template<class X>
class Lnode{
public:
X value;
Lnode * next;
};

template<class Y>
class linkedlist{
Lnode<Y> *head;
public:
linkedlist();
~linkedlist();
void addNode(Y &); // insert a video
void deleteNode(Y &);
void updateNode(Y &);
void displayNode()co nst;
void searchNode(cons t Y &);
};

class VideoTape{

string name;
double time;
int year;
double price;
public:
VideoTape();
VideoTape(strin g);
~VideoTape();

friend istream& operator >>(istream &,VideoTape &);
friend ostream& operator <<(ostream &,const VideoTape &);

friend bool operator < (const VideoTape &, const VideoTape &);
friend bool operator > (const VideoTape &, const VideoTape &);
friend bool operator != (const VideoTape &, const VideoTape &);
friend bool operator == (const VideoTape &, const VideoTape &);

void changetime(doub le);
void changeyear(int) ;
void changeprice(dou ble);
};
template<class Y>
linkedlist<Y>:: linkedlist(){
head = NULL;
}

template<class Y>
linkedlist<Y>:: ~linkedlist(){
Lnode<Y> *nodePtr;
nodePtr = head;

while(nodePtr != NULL)
{
head = nodePtr->next;
delete nodePtr;
nodePtr = head;
}
}

template<class Y>
void linkedlist<Y>:: addNode(Y &n){
Lnode<Y> * newnode, * nodePtr, * previousNode;
newnode = new Lnode<Y>;
newnode->value = n;

// Empty linked list

if(!head)
{
head = newnode;
newnode->next = NULL;
totalnodes++;

}
// not empty list
else
{
nodePtr = head;

// If head's value is greater and not equal to n
if(nodePtr->value > n && nodePtr->value != n){
previousNode = head;
head = newnode;
newnode->next = previousNode;
totalnodes++;
}

else{
// cycle through numbers while he pointer's value is less than n,
// and, also while the pointer's value does not equal n

while(nodePtr != NULL && nodePtr->value < n
&& nodePtr->value != n)
{
previousNode = nodePtr;
nodePtr = nodePtr->next;
}
// the while loop ends
// if the number is duplicate and the loop did not end at end of
// list
if(nodePtr != NULL)
if(nodePtr->value == n){
cout << "Tape name already exist" << endl;
cout << "Did not add tape" << endl;
return;
}

// if not then insert the newnode
previousNode->next = newnode;
newnode->next = nodePtr;
totalnodes++;
}
}
}
// Delete a node from the linked list
template<class Y>
void linkedlist<Y>:: deleteNode(Y &n)
{
Lnode<Y> *nodePtr, *previousnode;

//empty linked list
if(!head)
{
cout << "empty list" << endl;
return;
}

//delete the first node
if(head->value == n){
nodePtr = head->next;
delete head;
head = nodePtr;
totalnodes--;
}
else
{
nodePtr = head;

while(nodePtr != NULL && nodePtr->value != n){
previousnode = nodePtr;
nodePtr = nodePtr->next;
}
// if there is no number in the list that matches
// then the nodePtr points to NULL

if(nodePtr == NULL)
return;

previousnode->next = nodePtr->next;
delete nodePtr;
totalnodes--;
}
}

template<class Y>
void linkedlist<Y>:: updateNode(Y &n){
Lnode<Y> * nodePtr;
char choice;

double tmptime;
int tmpyear;
double tmpprice;

nodePtr = head;

if(!head){
cout << "The list is empty" << endl;
}
else{
while(nodePtr != NULL && nodePtr->value != n){
nodePtr = nodePtr->next;
}

if(nodePtr->value == n){
cout << nodePtr->value << endl;
cout << "Update the running time, year realeased, ";
cout << "or price" <<
endl;

cout << "a. Running time" << endl;
cout << "b. Year released" << endl;
cout << "c. Price" << endl;
cin.clear();
cin >> choice;
while(toupper(c hoice) != 'A' && toupper(choice) != 'B'
&& toupper(choice) != 'C'){

cout << "Invalid choice" << endl;
cout << "Please try again" << endl;
cout << "Update the running time, year realeased, ";
cout << "or price" <<
endl;

cout << "a. Running time" << endl;
cout << "b. Year released" << endl;
cout << "c. Price" << endl;
cin.clear();
cin >> choice;
}
switch(choice){
case 'A':
cout << "Enter the new running time" << endl;
cin >> tmptime;
nodePtr->value.changeti me(tmptime);
break;
case 'B':
cout << "Enter the new Year released" << endl;
cin >> tmpyear;
nodePtr->value.changeye ar(tmpyear);
break;
case 'C':
cout << "Enter the new Price" << endl;
cin >> tmpprice;
nodePtr->value.changepr ice(tmpprice);
break;
}
}
else if(nodePtr == NULL){
cout << "The video tape does not exist in the list";
cout << endl;
}
}
}

template<class Y>
void linkedlist<Y>:: displayNode()co nst {

Lnode<Y> * nodePtr;

nodePtr = head;

// Empty list

if(!head){
cout << "The list is empty" << endl;
return;
}
else{

cout << "Total of video tapes:" << totalnodes << endl;
cout << "Name\t\tRunnin g Time\tYear Released\tPrice " << endl;

while(nodePtr != NULL){
cout << nodePtr->value;
nodePtr = nodePtr->next;
}
cout << endl;
}
}

template<class Y>
void linkedlist<Y>:: searchNode(cons t Y &n){ // copyright by john cho
Lnode<Y> *nodePtr;

nodePtr = head;

// Empty list

if(!head){
cout << "The list is empty" << endl;
return;
}
else{
while(nodePtr != NULL && nodePtr->value != n){
nodePtr = nodePtr->next;
}

if(nodePtr->value == n)
cout << nodePtr->value;
else{
cout << "There is no such video tape in the list" << endl;
}
}
}


VideoTape::Vide oTape(){
time = 0;
year = 0;
price = 0;
}

VideoTape::Vide oTape(string n){
name = n;
time = 0;
year = 0;
price = 0;
}

VideoTape::~Vid eoTape(){
}
istream& operator >>(istream &in, VideoTape &vtape){
cout << "Enter Video Tape name" << endl;
in >> vtape.name;
cout << "Enter Running time" << endl;
in >> vtape.time;
cout << "Enter release year" << endl;
in >> vtape.year;
cout << "Enter price" << endl;
in >> vtape.price;

return in;
}

ostream& operator <<(ostream &out, const VideoTape &vtape2){
out << vtape2.name;
out << "\t\t";
out << vtape2.time;
out << "\t\t";
out << vtape2.year;
out << "\t\t$";
out << vtape2.price;
out << endl;

return out;
}
bool operator < (const VideoTape &a, const VideoTape &b){
return a.name < b.name;
}

bool operator > (const VideoTape &a, const VideoTape &b){
return a.name > b.name;
}

bool operator != (const VideoTape &a, const VideoTape &b){
return a.name != b.name;
}

bool operator == (const VideoTape &a, const VideoTape &b){
return a.name == b.name;
}
void VideoTape::chan getime(double t){
time = t;
}

void VideoTape::chan geyear(int y){
year = y;
}

void VideoTape::chan geprice(double p){
price = p;
}

int main(){

linkedlist<Vide oTape> thelist;

VideoTape avideo;
char choice;
string tapename;
do{
cout << "Videotape SYSTEM" << endl;
cout << "a. Add" << endl;
cout << "b. Delete" << endl;
cout << "c. Update" << endl;
cout << "d. Display" << endl;
cout << "e. Search" << endl;
cout << "x. Exit" << endl;
cin >> choice;

while(toupper(c hoice) != 'A' && toupper(choice) != 'B' &&
toupper(choice) != 'C' && toupper(choice) != 'D' &&
toupper(choice) != 'E' && toupper(choice) != 'X'){

cout << "Invalid entry, Please try again" << endl << endl;
cout << "Videotape SYSTEM" << endl;
cout << "a. Add" << endl;
cout << "b. Delete" << endl;
cout << "c. Update" << endl;
cout << "d. Display" << endl;
cout << "e. Search" << endl;
cout << "x. Exit" << endl;
cin.clear(); // clear multiple letters in the cin stream
cin >> choice;
cout << endl;
}

if(toupper(choi ce) == 'A'){
cout << "Enter a video tape" << endl;
cin >> avideo;
thelist.addNode (avideo);
}
else if(toupper(choi ce) == 'B'){
cout << "Enter a video tape name" << endl;
cin.clear(); // clear the istream
cin >> tapename;
thelist.deleteN ode(VideoTape(t apename));
}
else if(toupper(choi ce) == 'C'){
cout << "Enter a video tape name" << endl;
cin.clear(); // clear the istream
cin >> tapename;
thelist.updateN ode(VideoTape(t apename));
}
else if(toupper(choi ce) == 'D')
thelist.display Node();
else if(toupper(choi ce) == 'E'){
cout << "Enter a video tape name" << endl;
cin.clear();
cin >> tapename;
thelist.searchN ode(VideoTape(t apename));
}

}while(toupper( choice) != 'X');

return 0;

}
Jul 22 '05 #1
3 1950
John Cho wrote:
/* This program is a database program that will store
video tape names, minutes, year released, and price
I want it to be professional so that *YOU* will want
to buy it and use it for a video store, j/k about that
but i want it to be professional */
// note to leor, display works fine, you must have
// pressed update


You are using linked lists, why not use vectors instead? It would be
more crash safe that way and code would be more simpler (=less bugs) and
it would be faster for you to make (=cheaper).
---
Questions like this would be better if they would tell what kind of
format should be used, and for example am I suppose to give time in
seconds, minutes or hours?

Enter Running time
Enter release year
Enter price
---
When adding new tape, it tells me that name is used after I have given
all information. That makes more extra work for me.
---
Program doesn't save tapes, that also needs to be fixed if this is going
to be used in real life.
---
Program crashed when I inserted one video with name "video1" and then
tried to search for it with a name "vid"

Enter Video Tape name
video1
Enter Running time
1
Enter release year
1
Enter price
1

e
Enter a video tape name
vid
Segmentation fault
---
So suggestions: Rewrite your program using vector or something similar
and fix your user interface.
Jul 22 '05 #2
John Cho wrote:
/* This program is a database program that will store
video tape names, minutes, year released, and price
I want it to be professional so that *YOU* will want
to buy it and use it for a video store, j/k about that
but i want it to be professional */


My first thought is that if you want it to be professional you should
use the standard library instead of implementing your own linked list.

Second thought was that input operators should not do output.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #3
On Mon, 12 Apr 2004 19:35:44 GMT, John Cho <jo*****@johnch o.us> wrote:
// note to leor, display works fine, you must have
// pressed update

Whoops, so I must've. OK, so let's say you select "update" and then change
your mind. You still don't provide an "escape" mechanism.

This didn't compile with Comeau, BTW, but the reason is subtle (and
evidently the issue is not even diagnosed under certain other compilers):
when you call deleteNote and updateNode, you pass a temporary VideoTape
object as argument; the corresponding parameters are declared as
reference-to-non-const, and that is a no-no. To make it kosher, just add a
"const" in the definitions and declarations for those two functions. Better
yet, change the design so all you pass in situations such as those is the
tapename directly (by const ref, optimally), avoiding the construction of
that temporary VideoTape object for no good reason.

If I have time to look at more of this I might, but that's all I've looked
at for now.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #4

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

Similar topics

3
5250
by: Kelvin Klein | last post by:
Is there a visualization tool for C program out there? Is there a visualization tool for the language of one of the crossposted newsgroup out there? I am a refuge from comp.lang.c, kicked out without being told where to go. I am sure one of the kind souls would be glad to help. The original message below was written for C but I am now going...
9
2281
by: John Cho | last post by:
// CHO, JOHN #include<iostream> class fracpri{ int whole; int numer; int denom;
3
369
by: John Cho | last post by:
/* This program is a database program that will store video tape names, minutes, year released, and price I want it to be professional so that *YOU* will want to buy it and use it for a video store, j/k about that but i want it to be professional */ // note to leor, display works fine, you must have // pressed update #include<iostream>
2
1202
by: George Hester | last post by:
http://www.bazon.net/mishoo/articles.epl?art_id=824 Do you think this could cause an effect such as a page with pulsating scroll bars? So bad that the mouse cannot pull the scroll bar down down to show remaing parts of the page? It is too busy pulsating. -- George Hester _________________________________
6
8359
by: Juan Romero | last post by:
Guys, Sometimes when you want to open a file, the file is locked for editing for some reason. You are able to see the contents of the file (depending on the program you are using) but you are not able to save your changes to it. I am looking to make a program that can tell me what program is locking the file. Does anyone know how to do...
4
3325
by: gstaats | last post by:
I know that that exact subject is on the MSDN website - I have read through those chapters and understand how to implement JRO replication. My question is what tools or software does one need inorder to use the extensions and commands referenced? The Access 2002 VBA editor will not recognize any methods of 'JRO'. The first command line...
5
3839
by: efffemm | last post by:
A few years ago, I heard of a program (maybe it is a plugin for a well-know HTML editor) that cleans up the shit generated when you save as html from Microsoft Word or PowerPoint, so that it can be viewed in something other than IE6 .... but I forgot what it was called. Any ideas what it is?
3
1778
by: Dean Slindee | last post by:
Need to write a standalone application that processes data once per day. Looking for the application program types available that would satisfy these requirements: Requirements: 1. Unattended processing that looks for rows in tables in a SQL Server database that is updated in batch once per day via another company's daily process. The newly...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.