J
Jordan Tiona
Alright, so here is some code. This is for a school project, and my teacher
is unreachable, so I'm posting this here. There are a few unfinished
functions, but I'll get to those soon. I compiled and ran this code, and I'm
getting an exception error on the "GetNext" function. I'm assuming it is
because I am forgetting to define a pointer before using it, but I can't
figure out where.
W7Graded.cpp
/*------------------------------------------------------/*
/* Workshop 7 -- Graded Project /*
/* Jordan Tiona /*
/* Last Updated April 17, 2006 /*
/*------------------------------------------------------*/
//Included Files
#include <iostream>
#include <stdio.h>
#include "W7Graded.h"
using namespace std;
//Function Prototypes
void PrintData();
void EnterData();
void SaveData();
void LoadData();
//Global Variables
cdData* cd; //Linked List
int main(){
int choice;
bool quit = false;
while(quit == false){
system("cls");
cout << "Welcome to CD Tracker \n\n";
cout << "What would you like to do?\n";
cout << "\t(1)Print Current Data\n";
cout << "\t(2)Enter New Data\n";
cout << "\t(3)Save Current Data\n";
cout << "\t(4)Load Data\n";
cout << "\t(5)Exit\n";
cin >> choice;
switch(choice){
case 1: PrintData();
break;
case 2: EnterData();
break;
case 3: SaveData();
break;
case 4: LoadData();
break;
case 5: quit = true;
break;
default: cout << "\n Invalid choice. Please try again\n";
}
}
return 1;
}
void PrintData(){
}
void EnterData(){
bool stop = false;
char* tempStr;
int tempInt;
cdData* curNode = cd;
char yn;
//Get to the end of the linked list first
while(curNode->GetNext() == NULL){ //If there isn't anything after this
node, then this is the end of the list
curNode = curNode->GetNext(); //Go to the next Node
}
while(stop == false){
system("cls");
//Add a new node
curNode->SetNext(new cdData());
curNode = curNode->GetNext();
cout <<"\nName of CD: ";
cin.getline(tempStr, MAX_LENGTH);
curNode->SetName(tempStr);
cout <<"\n\nName of Artist: ";
cin.getline(tempStr, MAX_LENGTH);
curNode->SetArtist(tempStr);
cout <<"\n\nYear Released: ";
cin >> tempInt;
curNode->SetYear(tempInt);
system("cls");
cout <<"Enter another CD? (Y/N)\n";
cin >> yn;
if(yn == 'Y' || 'y')
stop = false;
else
stop = true;
}
}
void SaveData(){
}
void LoadData(){
}
And now, W7Graded.h
//CD Data
const int MAX_LENGTH = 21;
class cdData {
private:
//CD Data
char* cdName;
char* artist;
int year;
//Linked List Data
cdData* next;
public:
//Constructor/Destructor
cdData(){next = NULL;}
~cdData(){}
//Accessors
char* GetName(){return cdName;}
char* GetArtist(){return artist;}
int GetYear(){return year;}
void SetName(char* newName){cdName = newName;}
void SetArtist(char* newName){artist = newName;}
void SetYear(int newYear){year = newYear;}
cdData* GetNext(){return next;}
void SetNext(cdData* newNext){next = newNext;}
};
Thanks in advance for your help. I really need to get this done.
is unreachable, so I'm posting this here. There are a few unfinished
functions, but I'll get to those soon. I compiled and ran this code, and I'm
getting an exception error on the "GetNext" function. I'm assuming it is
because I am forgetting to define a pointer before using it, but I can't
figure out where.
W7Graded.cpp
/*------------------------------------------------------/*
/* Workshop 7 -- Graded Project /*
/* Jordan Tiona /*
/* Last Updated April 17, 2006 /*
/*------------------------------------------------------*/
//Included Files
#include <iostream>
#include <stdio.h>
#include "W7Graded.h"
using namespace std;
//Function Prototypes
void PrintData();
void EnterData();
void SaveData();
void LoadData();
//Global Variables
cdData* cd; //Linked List
int main(){
int choice;
bool quit = false;
while(quit == false){
system("cls");
cout << "Welcome to CD Tracker \n\n";
cout << "What would you like to do?\n";
cout << "\t(1)Print Current Data\n";
cout << "\t(2)Enter New Data\n";
cout << "\t(3)Save Current Data\n";
cout << "\t(4)Load Data\n";
cout << "\t(5)Exit\n";
cin >> choice;
switch(choice){
case 1: PrintData();
break;
case 2: EnterData();
break;
case 3: SaveData();
break;
case 4: LoadData();
break;
case 5: quit = true;
break;
default: cout << "\n Invalid choice. Please try again\n";
}
}
return 1;
}
void PrintData(){
}
void EnterData(){
bool stop = false;
char* tempStr;
int tempInt;
cdData* curNode = cd;
char yn;
//Get to the end of the linked list first
while(curNode->GetNext() == NULL){ //If there isn't anything after this
node, then this is the end of the list
curNode = curNode->GetNext(); //Go to the next Node
}
while(stop == false){
system("cls");
//Add a new node
curNode->SetNext(new cdData());
curNode = curNode->GetNext();
cout <<"\nName of CD: ";
cin.getline(tempStr, MAX_LENGTH);
curNode->SetName(tempStr);
cout <<"\n\nName of Artist: ";
cin.getline(tempStr, MAX_LENGTH);
curNode->SetArtist(tempStr);
cout <<"\n\nYear Released: ";
cin >> tempInt;
curNode->SetYear(tempInt);
system("cls");
cout <<"Enter another CD? (Y/N)\n";
cin >> yn;
if(yn == 'Y' || 'y')
stop = false;
else
stop = true;
}
}
void SaveData(){
}
void LoadData(){
}
And now, W7Graded.h
//CD Data
const int MAX_LENGTH = 21;
class cdData {
private:
//CD Data
char* cdName;
char* artist;
int year;
//Linked List Data
cdData* next;
public:
//Constructor/Destructor
cdData(){next = NULL;}
~cdData(){}
//Accessors
char* GetName(){return cdName;}
char* GetArtist(){return artist;}
int GetYear(){return year;}
void SetName(char* newName){cdName = newName;}
void SetArtist(char* newName){artist = newName;}
void SetYear(int newYear){year = newYear;}
cdData* GetNext(){return next;}
void SetNext(cdData* newNext){next = newNext;}
};
Thanks in advance for your help. I really need to get this done.