On-line: гостей 0. Всего: 0 [подробнее..]
Программисты всех стран, объединяйтесь!

АвторСообщение



ссылка на сообщение  Отправлено: 10.11.12 14:59. Заголовок: Hi ! I Newbie here !


From cplusplus.com .
I saw your profile and it's give me the link so i review at here !
Here is to help student step by step right?
I have 1 assignment and hope that someone will help me until finish it ?
It's not hard but quite hard for me I think..

so I post what I done so far
#include <iostream> 
#include <string>
#include <conio.h>

using namespace std;

struct RentalRecord{

string customerName;
string CDTitle;
RentalRecord *next;
}

class RentalStore{


public:
void addRecord();
void RetrievalRecord();
void deleteRecord();

RentalStore();
~RentalStore();
void isEmpty();
void clear();
};

struct TreeNode{
string CollectionCDTitle;
TreeNode *left;
TreeNode *right;
}

class Tree{
private:
TreeNode *root;
public:
Tree();
~Tree();

void checkTreeRecord();
void writeTreeRecord();

};


and I saw other thread can post the question as well , I post it instead my poor explanation
A new CD Rental store needs a program to keep track of its CD titles and rental information. The program should be able to perform the following operations.

1. Rent a CD
2. Return a CD
3. Print all the CDs available in the store
4. Print all rental information
5. Print specific rental information
The rental information is to be kept in a struct called RentalRecord containing the members representing customer’s name and CD title.

Create a linked-list class to represent the list of rental records for the store. The class should provide the following major operations:

 Allow new records to be added to the end of the list.
 Allow a retrieval of a record using an iterator
 Allow deletion of a record pointed by the iterator




Include also other functions that are needed by the class such as constructors, destructor, isEmpty(), and clear() functions.

The rent option should create a new rental record and add to the linked-list. The return option should delete the rental record from the linked-list. All printing rental options should use the iterator to retrieve the record(s) from the list.

Create a binary search tree class to store a collection of CD titles. A binary tree object should be created at the starting of the program. The entries to this tree are to be read from a text file called CDRecord.txt. When a rental operation is requested, the CD title should be checked against the tree (a search is done) to see if the title exists or not. If the title does not exist, the program should prompt the user either to add the new title, change to another title, or cancel the rental request. If add a new title option is chosen, then the title should be added to the tree. Before the program ends, send all entries of the tree to the CDRecord.txt file and overwrite any existing content.



Did I wrong for my class and Tree implementation so far?
I want to do it step by step !

Спасибо: 0 
ПрофильЦитата Ответить
Ответов - 18 [только новые]





ссылка на сообщение  Отправлено: 10.11.12 15:37. Заголовок: Let consider for exa..


Let consider for example class RentalStore

class RentalStore{ 
public:
void addRecord();
void RetrievalRecord();
void deleteRecord();
RentalStore();
~RentalStore();
void isEmpty();
void clear();
};


First of all it would be better when constructors and destructors are placed before other methods in a class definition.

Your class has no data members. Usually if a class has no data members it specifiies an interface that will be inherited by other derived classes. In this case it is better to define such a class as abstract.

Further let consider method addRecord. What does it add? I think that it should have some kind of a parameter that will specify what is added.

The same is valid for methods RetrievalRecord and deleteRecord that is they should have some kind of parameters.

Method isEmpty should report whether an object of the class contains some useful data. So its return type shall be bool instead of void as you speciified.

And only method clear is declared in appropriate way.

Other your code I did not see because I think you should update at least the definition of this class.


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 10.11.12 15:44. Заголовок: can help to see my q..


can help to see my question for a moment?
Create a linked-list class to represent the list of rental records for the store. The class should provide the following major operations:

is that mean create a linked list like
RentalRecord* list;
Is that correct?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 10.11.12 15:53. Заголовок: Yes you should inclu..


Yes you should include a private data member of type RentalRecord *. It is not important how you will name it either list, header or something else.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 10.11.12 16:10. Заголовок: The rent option shou..


The rent option should create a new rental record and add to the linked-list. The return option should delete the rental record from the linked-list. All printing rental options should use the iterator to retrieve the record(s) from the list.

From this statement mean,
the function addRecord() should pass the
addRecord( RentalRecord * ) to the linked list. Am I correct?

and the return option is mean that
deleteRecord( RentalRecord * ) also right?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 10.11.12 16:14. Заголовок: I do not know what a..


I do not know what are "rent option" and "return option" but I think you are right.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.12 06:25. Заголовок: sorry for my late re..


sorry for my late reply . the
rent option = user rent a cd and add a record
return option = user return a cd and delete the rent record

so i did it until here

for my add and delete
#include "cd.h" 

void RentalStore ::addRecord(RentalRecord *){

RentalRecord *newRental;
newRental = new RentalRecord;

system( "cls" );
cout << "\tAdd New Record\n-----------------------------" << endl
<< "Enter title : ";
getline( cin, newRental->CDTitle );
newRental->link = current->link;
}

void RentalStore ::deleteRecord(RentalRecord *){

int choice = 0;
RentalRecord *deleteRecord;
deleteRecord = new RentalRecord;

cout << "Enter title : ";
getline( cin , deleteRecord->CDTitle );
//Find record


cout << "\n1.Return CD " << endl
<< "2.Cancel " << endl << endl
<< "Enter Choice : ";
cin >> choice;

do{
switch( choice ){
case 1:
deleteRecord = current->link;
current->link = deleteRecord->link;
delete deleteRecord;
break;
case 2:
cout << endl;
break;
default:
cout << "Invalid Input ! Please re-enter ! " << endl;
break;
}
}while( choice != 0 || choice !=1 || choice != 2 );

}


I refer to some information on web , by the way , where should i declare my current pointer ?
#include <iostream> 
#include <string>
#include <conio.h>
#include <fstream>

using namespace std;

struct RentalRecord{

string customerName;
string CDTitle;
RentalRecord *link;
}

class RentalStore{
RentalRecord *list;

public:
RentalStore();
~RentalStore();
void addRecord( RentalRecord *);
void RetrievalRecord();
void deleteRecord(RentalRecord *);
bool isEmpty();
void clear();
};

struct TreeNode{
string CollectionCDTitle;
TreeNode *left;
TreeNode *right;
}

class Tree{
private:
TreeNode *root;
public:
Tree();
~Tree();

void checkTreeRecord();
void writeTreeRecord();

};


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.12 12:20. Заголовок: Why these functions ..


Why these functions

void RentalStore ::addRecord(RentalRecord *){
void RentalStore ::deleteRecord(RentalRecord *){

do declare parameters but they are not used in the functions?

As I think the functions have to have as a parameter a title of CD. So in my opinion it is more natural if they would be declared as

void RentalStore ::addRecord( std::string title ){
void RentalStore ::deleteRecord( std::string title ){




Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.12 17:04. Заголовок: void RentalStore ::a..


void RentalStore ::addRecord(string title){ 

RentalRecord *newRental;
newRental = new RentalRecord;

system( "cls" );
cout << "\tAdd New Record\n-----------------------------" << endl
<< "Enter title : ";
getline( cin, title );
newRental->link = current->link;
}


the current pointer how should I declare as well?
because I referring other sources of c++
http://geekswithblogs.net/MarkPearl/archive/2010/02/20/linked-lists-in-c.aspx

as he didn't mention that where the current should declare at

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.12 18:30. Заголовок: It depends on whethe..


It depends on whether you will check duplicate names in your container and whether the elements shall be ordered for exmplae by CD name.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.12 18:53. Заголовок: can provide an examp..


can provide an example for my code for me >< ?
hehe ..
just want to have some idea and to do .. mind?? and thank you^^

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 17.11.12 02:29. Заголовок: Your defined RentalR..


Your defined RentalRecord that contains pointer to next RentalRecord

struct RentalRecord{ 
string customerName;
string CDTitle;
RentalRecord *link;
};


So it means that you are going to use siingle-linked list. If you need no any order for the list of RentalRecord(s) then you can insert a new record at the very beginning of the liist. If you have to keep some order then you should at first find an appropriate slot where the new record will be added. In this case there is sense to have pointer with name current before which the new record will be added.
As you are using the single linked list then you should use the linear search where to insert new record. In this case you should define operator < to compare records. So a question arises what data member will be used in the comparision?
.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 17.11.12 07:44. Заголовок: You are right. i hav..


You are right. i having problem with the *current there. because I referring to the sources of the link that i provide. but i don't know where should i declare the pointer of current at where .
If you have to keep some order then you should at first find an appropriate slot where the new record will be added. In this case there is sense to have pointer with name current before which the new record will be added.
sorry for keep repeating . what's the meaning? and
do you said i should define a overloading operator as well?


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 20.11.12 22:06. Заголовок: Let again consider s..


Let again consider structure RentalRecord

 struct RentalRecord{ 
string customerName;
string CDTitle;
RentalRecord *next;
}


I do not think that it shall be accessible outside class RentalStore. So I would declare it as a nested declaration that is I would declare it inside class RentalStore as its member.

To create a new object of type RentalRecord we should supply two values customerName and CDTitle. I do not think that there is any sense to define an object of this type with empty values of customerName and CDTitle. So it would be useful to define a constructor with two parameters. For example

 struct RentalRecord{ 
RentalRecord( string title, string name = "" ) : CDTitle( title ), customerName( name ), next( 0 ) {}
string CDTitle;
string customerName;
RentalRecord *next;
}


So that to add new record you should ask a CD title and maybe a customer name .

So I suggest to change your classes the following way
1) make RentalRecord as a nested declaration inside RentalStore;
2) add the constructor shown above to RentalRecord.

Function addRecord can be done the following way

 void RentalStore ::addRecord(string title) 
{
system( "cls" );
cout << "\tAdd New Record\n-----------------------------" << endl
<< "Enter title : ";
getline( cin, title );

RentalRecord *newRental = new RentalRecord( title );
if ( list ) newRental->next = list;
list = newRental;
}


This code places a new record always at the beginning of the list. It also does not check whether a record with the same CDTitle already exists. I think you can write the corresponding function yourself that will check whether a record with the same CDTitle already exists.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 21.11.12 04:37. Заголовок: but my question ment..


but my question mentioned that i should use my class name Store to do the function of add record
Create a linked-list class to represent the list of rental records for the store. The class should provide the following major operations[.b]
but yours way is inside the RentalStore right?

and do you mean the structure should be inside the class of RentalStore?
should i put in private or public? because i got used that way before and put as public and they told me not a good practice ?

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 21.11.12 10:14. Заголовок: You should make stru..


You should make structure RentalRecord as a private member of class RentalSrore. For example


class RentalStore{ 
struct RentalRecord{
RentalRecord( string title, string name = "" ) : CDTitle( title ), customerName( name ), next( 0 ) {}
string CDTitle;
string customerName;
RentalRecord *link;
} *list;
public:
RentalStore();
~RentalStore();
void addRecord( const string &title );
void RetrievalRecord( const string &title ) const;
void deleteRecord( const string &title );
bool isEmpty() const;
void clear();
};


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 21.11.12 11:19. Заголовок: I'm apologize fo..


I'm apologize for it . Only now i know how to declare it using structure ..
can u help me something out?
for my concept . for the binary search tree for this question . is to store a collection of CD titles. A binary tree object should be created at the starting of the program.

for BST , the *right should be always larger than root and *left should be smaller then root and so on right? can u help me for this?

because it need to use strcmp(root , other )
if( root != NULL ) 
addRoot( node );
}
else{
addRight or left
}


please help ..

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 23.11.12 10:41. Заголовок: void RentalStore ::..


void RentalStore :: addRecord(string &title , string &customerName){ 

system( "cls" );
cout << "\tAdd New Record\n-----------------------------" << endl << endl
<< "Enter Customer Name : ";
getline( cin,customerName );
cout << "Enter title : ";
getline( cin, title );
RentalRecord *newRental = new RentalRecord( title , customerName );
if ( theRental != NULL ){
RentalRecord *temp = theRental;
while( temp->next ){
temp = temp->next;
}
temp->next = newRental;
}
else
theRental = newRental;
}

void RentalStore ::deleteRecord(string &deleteTheRecord , string &customerName){

system( "cls" );
int choice = 0;
bool found = 1;
RentalRecord *previous_rental = NULL;
RentalRecord *current_rental = theRental;

cout << "\tAdd New Record\n-----------------------------" << endl << endl;

cout << "Enter Customer Name : ";
getline ( cin , customerName );

cout << "Enter title : ";
getline( cin , deleteTheRecord );

while( !current_rental != NULL ){
if ( current_rental->customerName == customerName ){
if( current_rental->RecordTitle == deleteTheRecord ){
cout << "Found Record ! " << endl;
found = 1;
break;
}
}
else{
cout << "No any Record found ! " << endl << endl;
previous_rental = current_rental;
current_rental = current_rental->next;
found = 0;
}
}

if( found ){
cout << "Customer Name : " << current_rental->customerName << endl
<< "Borrowed CD : " << current_rental->RecordTitle << endl << endl;
if( current_rental != NULL ){
if( previous_rental !=NULL ){
previous_rental->next = current_rental->next;
}
else{
theRental = current_rental->next;
}
delete current_rental;
}
}
}


The deleteRecord is purposely when a customer Return a CD then only delete
so If the customer Name not inside the record it will be display that no record found , else it will go to second if to compare the title again. if both if are true , only delete the record .
i think I did it with this ? or any mistake i make again? T.T

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 26.11.12 17:42. Заголовок: here what i Did for ..


here what i Did for my tree
struct TreeNode{ 
string cdTitle;
TreeNode *left;
TreeNode *right;
};

class Tree{
private:
TreeNode *root;
public:
Tree();
~Tree();

bool Empty();
void Display();

};

Tree :: Tree (){
root = NULL;
}

bool Tree :: Empty(){
if ( root == NULL )
return true;
else
return false;
}

void addNode( TreeNode*& tree , string title ){
if( tree == NULL ){
tree = new TreeNode;
tree->left = NULL;
tree->right = NULL;
tree->cdTitle = title;
}
else if( title < tree->cdTitle )
addNode( tree->left , title );
else
addNode( tree->right , title );
}


void Print( TreeNode*& tree ){
if( tree != NULL ){
Print( tree->left );
cout << tree->cdTitle;
Print( tree->right );
}
}

void Tree :: Display(){
Print ( root );
}


can show me that how I read from a file that CDRecord.txt and use BST to store out? i know those easy ifstream stuff. don't really get how to show out and store them using BST . mind to teach?
My txt should be show like this :
Titanic 
Hello World
Dancing world
Michael Jackson
Underground
Dive
Sorry , I'm Falling love on her


just the CD title. that's all

Спасибо: 0 
ПрофильЦитата Ответить
Ответ:
1 2 3 4 5 6 7 8 9
большой шрифт малый шрифт надстрочный подстрочный заголовок большой заголовок видео с youtube.com картинка из интернета картинка с компьютера ссылка файл с компьютера русская клавиатура транслитератор  цитата  кавычки моноширинный шрифт моноширинный шрифт горизонтальная линия отступ точка LI бегущая строка оффтопик свернутый текст

показывать это сообщение только модераторам
не делать ссылки активными
Имя, пароль:      зарегистрироваться    
Тему читают:
- участник сейчас на форуме
- участник вне форума
Все даты в формате GMT  3 час. Хитов сегодня: 28
Права: смайлы да, картинки да, шрифты да, голосования нет
аватары да, автозамена ссылок вкл, премодерация откл, правка нет