hi, i'm having problems with my homework. I have to create a Base classes from which 2 classes have to be derived, then i have to write a program to test their function. The problem that i'm having is that i'm taking the input from the keyboard and passing it to a function in the base class. I dont get any error/warning messages but when i run the debug, it stops when it takes the first keyboard input. Programs stops when the input from line 33 (when B/b is selected) or 47 (when R/r is selected), of the Library.cpp file, is copied on the Holding.cpp file line 28 "strcpy_s(title, strlen(name), name)." Any suggestion on what could it be????
[LIST=1]
[*]//holding.h - base class
[*]#ifndef _HOLDING_H
[*]#define _HOLDING_H
[*]class Holding
[*]{
[*] protected:
[*] char *title;
[*] int call;
[*] public:
[*] Holding();// {call = 0;}
[*] Holding(const Holding& hold);// : title(hold.title), call(hold.call) { }
[*] ~Holding();
[*] virtual void print() = 0;
[*] void setCall(int num);
[*] void setTitle(const char *name);
[*]};
[*]#endif
[/LIST]
[LIST=1]
[*]#include <iostream>
[*]#include <string.h>
[*]#include "holding.h"
[*]#include <stdio.h>
[*]using namespace std;
[*]Holding::Holding()
[*]{
[*] call = 0;
[*]}
[*]Holding::Holding(const Holding &hold)
[*]{
[*] title = new char [strlen(hold.title) + 1];
[*] strcpy_s(title, strlen(hold.title), hold.title);
[*] call = hold.call;
[*]}
[*]Holding::~Holding()
[*]{
[*] delete [] title;
[*] call = 0;
[*]}
[*]void Holding::setCall(int num)
[*]{
[*] call = num;
[*]}
[*]void Holding::setTitle(const char *name)
[*]{
[*] title = new char [strlen(name) + 1];
[*] strcpy_s(title, strlen(name), name);
[*]}
[/LIST]
[LIST=1]
[*]//book.h - derived class 1
[*]#ifndef _BOOK_H
[*]#define _BOOK_H
[*]#include "holding.h"
[*]class Book : public Holding
[*]{
[*] private:
[*] char *author;
[*] public:
[*] Book() : Holding() {author = new char;};
[*] Book(const Book& bk) : Holding(bk) {author = new char;}
[*] ~Book();
[*] virtual void print();
[*] void setAuthor(const char *auth);
[*]};
[*]#endif
[/LIST]
[LIST=1]
[*]#include "book.h"
[*]#include "holding.h"
[*]#include <iostream>
[*]#include <string.h>
[*]#include <stdio.h>
[*]using namespace std;
[*]void Book::setAuthor(const char *auth)
[*]{
[*] author = new char[strlen(auth) + 1];
[*] strcpy_s(author, strlen(auth), auth);
[*]}
[*]Book::~Book()
[*]{
[*] delete [] author;
[*]}
[*]void Book::print()
[*]{
[*] cout<< "BOOK: " << author << " \"" << title << "\" " << call << endl;
[*]}
[/LIST]
[LIST=1]
[*]//record.h - derived class 2
[*]#ifndef _RECORD_H
[*]#define _RECORD_H
[*]#include "holding.h"
[*]class Record : public Holding
[*]{
[*] public:
[*] enum format {L, C, R, D};
[*] private:
[*] char *performer;
[*] format frm;
[*] static char *snames[4];
[*] public:
[*] Record() : Holding() {performer = new char;}
[*] Record(const Record& rec) : Holding(rec) {performer = new char;}
[*] ~Record();
[*] virtual void print();
[*] void setPerformer(const char *auth);
[*] void setFormat(char f);
[*]};
[*]#endif
[/LIST]
[LIST=1]
[*]//record.cpp
[*]#include "holding.h"
[*]#include "record.h"
[*]#include <iostream>
[*]#include <string.h>
[*]#include <stdio.h>
[*]using namespace std;
[*]char *Record::snames[4]= {"LP", "Cassette", "Reel-to-Reel", "CD" };
[*]void Record::setPerformer(const char *auth)
[*]{
[*] performer = new char [strlen(auth) + 1];
[*] strcpy_s(performer, strlen(auth), auth);
[*]}
[*]Record::~Record()
[*]{
[*] delete [] performer;
[*]}
[*]void Record::setFormat(char f)
[*]{
[*] if (f == 'l' || f == 'L')
[*] frm = L;
[*] else if (f == 'c' || f == 'C')
[*] frm = C;
[*] else if (f == 'r' || f == 'R')
[*] frm = R;
[*] else if (f == 'd' || f == 'D')
[*] frm = D;
[*]}
[*]void Record::print()
[*]{
[*] cout << "\"" << title << "\" " << performer << " (" << snames[frm] << ") " << call << endl;
[*]}
[/LIST]
[LIST=1]
[*]//record.h
[*]#ifndef _LIBRARY_H
[*]#define _LIBRARY_H
[*]#include "book.h"
[*]#include "record.h"
[*]#include "holding.h"
[*]void main();
[*]#endif
[/LIST]
[LIST=1]
[*]#include <iostream>
[*]#include <string.h>
[*]#include <stdio.h>
[*]#include "library.h"
[*]#include "book.h"
[*]#include "record.h"
[*]#include "holding.h"
[*]using namespace std;
[*]Holding *holdLib[5];
[*]Book *bk;
[*]Record *rec;
[*]char select;
[*]const char *title;
[*]const char *name;
[*]int call;
[*]char format;
[*]void main()
[*]{
[*] //count = 5;
[*] //holdLib = new Holding [5];
[*] cout << "Enter holdings to be stored in a list: " << endl;
[*] cout << endl;
[*] for (int c = 0; c < 5; c++)
[*] {
[*] title = new char[100];
[*] name = new char[100];
[*]
[*] cout << "Enter B for book, R for recording: ";
[*] cin >> select;
[*] if (select == 'B' || select == 'b')
[*] {
[*] bk = new Book;
[*]
[*] cout << "Enter book title: ";
[*] cin >> title;
[*] bk->setTitle(title);
[*] cout << "Enter book author: ";
[*] cin >> name;
[*] bk->setAuthor(name);
[*] cout << "Enter call number: ";
[*] cin >> call;
[*] bk->setCall(call);
[*] holdLib[c] = bk;
[*] }
[*] else if (select == 'R' || select == 'r')
[*] {
[*] rec = new Record;
[*] cout << "Enter record title: ";
[*] cin >> title;
[*] rec->setTitle(title);
[*] cout << "Enter performer: ";
[*] cin >> name;
[*] rec->setPerformer(name);
[*] cout << "Enter format: (L)P, (C)assette, (R)eel-to-Reel, (D)isk: ";
[*] cin >> format;
[*] rec->setFormat(format);
[*] cout << "Enter call number: ";
[*] cin >> call;
[*] rec->setCall(call);
[*]
[*] holdLib[c] = rec;
[*] }
[*] else
[*] {
[*] cout << "You have enter the wrong selection: " << endl;
[*] c--;
[*] }
[*] }
[*] cout << endl;
[*] cout << "Here are the holdings: " << endl;
[*] cout << endl;
[*] for (int n = 0; n < 5; n++)
[*] {
[*] holdLib[n]->print();
[*] }
[*]}
[/LIST]