Jump to content

i need to correct my program

- - - - -

  • Please log in to reply
4 replies to this topic

#1
king_programmer

king_programmer

    Newbie

  • Members
  • Pip
  • 2 posts

write a class called Book to store the attributes of a book and do the required operations on it.In particular , it should have the following protected data members
title-string ,author -array of string ,size=4,ISBN-string,publisher-string,year of publiication-int.Note that ISBN is a 13 digit integer number and it is unique for every book.You can use a string for it

it should have a constructor function with default parameters ,set,and get function for each of the data members and a print function to print all the attributes of the book

B.Write a class called LibraryBook,which inherites the properties of the class Book with inheritance type as public . This class has the following additional data members

accession number(integer between 1 and 1000),rack number(integer between 1 and 100).Note that the rack number gives the rack on which the book is placed in the library

Include a constructor function with parameters , set and get functions for assession number and rack number and a print function to print all the attributes of a library book(including that of Book),!!!

c.write main function to test all functionalities of
your classs


This is my trying

can u help me

plzzzzzzzz

#include<iostream> 
#include<string> 
using namespace std; 
class Book 
{ 
protected: 
    string title; 
    string author[4]; 
    string ISBN; 
    string publisher; 
    int year,numofauthor; 
public: 
    Book(string t=" ",string auth[]={" "},string i=" " , string p,int y=2000); 
    void setTittle(string); 
    void setAuthor[](string); 
    void setisbn(string); 
    void setPublisher(string); 
    void setYear(int); 
    string getTittle(string&); 
    string getAuthor[](string&); 
    string getisbn(string&); 
    string getpublisher(string&); 
    int getYear(int&); 
    void print(); 
}; 

Book::Book(string t=" ",string auth[]={" "},string i=" " , string p, 
        int y=2000) 
{ 
    title=t; 
    for(int x=0; x<numauthor;x++) 
    author[x]=a[x]; 
    ISBN=i; 
    publisher=p; 
    year=y; 
} 

void Book::setTittle(string t) 
{ 
    tittle=t; 
} 

void Book::setAuthor[](string auth[]) 
{ 
     
    if(size>4) 
        size=4; 
    numauthor=size; 

    for (int i=0; i<size; i++) 
        author[i]=a[i]; 
} 
void Book::setisbn(string i) 
{ 
    ISBN=i; 
} 
void Book::publisher(string p) 
{ 
    publisher=p; 
} 
void Book::setYear(int y) 
{ 
    year=y; 
} 
string Book::getTitle() 
{ 
    return title; 
} 
string Book::getAuthor[]() 
{ 
    return author[]; 
} 
string Book::getisbn() 
{ 
    return ISBN; 
} 
string Book::getPublisher() 
{ 
    return publisher; 
} 
string Book::getYear() 
{ 
    return year; 
} 
string Book::print() 
{ 
    cout<<" Tittle :" << tittle <<endl; 
    cout<<" Author :" ; 
    for(int i=0;i<numofauthor;i++) 
    { 
        cout<<author[i]<<" "<<endl; 
    } 
    cout<<" ISBN :"<<ISBN<<endl; 
    cout<<" publisher "<< publisher<<endl; 
    cout<<" YEAR :"<<endl; 
} 

class LibarayBook: public Book 
{ 
protected: 
    int acc_num[1000]; 
    int rac_num[100]; 
public: 
    LibarayBook( int acc[]=0,int rac[]=0); 
    void setAcc_num[](int); 
    void setRac_num[](int); 
    int getAcc_num[](); 
    int getRac_num[](); 
    void print(); 
}; 

LibarayBook::LibarayBook(int acc[], int rac[],string t=,string auth[], 
                         string i= , string p,int y):Book(t,auth[],i,p,y) 

{ 
    acc_num=acc[]; 
    rac_num=rac[]; 
} 

void LibarayBook::setAcc_num[](int acc[]) 
{ 
    acc_num[]=acc[]; 
} 
void LibarayBook::setRac_num[](int rac[]) 
{ 
    rac_num[]=rac[]; 
} 
int LibarayBook::getAcc_num[]() 
{ 
    return acc_num[]; 
} 
int LibarayBook::getAcc_num[]() 
{ 
    return rac_num[]; 
} 
void LibarayBook::print() 
{ 
    cout<<"Book":<<endl; 
    Book::print(); 
    cout<<endl; 
    cout<<"accession number:"<<endl; 
        for(int i=0;i<1000;i++) 
            cout<<acc_num[i]<<endl; 
    cout<<" rack number :"<<endl; 
        for(int i=0;i<100;i++) 
            cout<<rac_num[i]<<endl; 
} 


int main() 
{ 
    LibarayBook L; 

     
    L.setYear(2010); 

    L.print(); 

    return 0; 
} 

Edited by WingedPanther, 17 July 2010 - 12:12 PM.


#2
artificial

artificial

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 624 posts
Could you describe your problem more precisely?

Greets,
artificial
Sometimes words ain't enough to express something. That's why computer scientists use double words.

#3
king_programmer

king_programmer

    Newbie

  • Members
  • Pip
  • 2 posts
I've got errors in this program and i don't know how i correct it??

can you help me??

do you have a proram ( microsoft visual c++ 6.0) ??

u can copy the program after that you will know what is the error in details!!!

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
First, please note that I added code tags to your post (the # button).
Second, VC++6.0 is VERY old and not standards compliant. You can download a more recent version for free.
Third, what are your errors?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
string Book::print() 
You don't return a string here, even though you declare it as such.

LibarayBook( int acc[]=0,int rac[]=0);
.
.
.
LibarayBook::LibarayBook(int acc[], int rac[],string t=,string auth[], 
                         string i= , string p,int y):Book(t,auth[],i,p,y)
You declare the constructor but never implement it, and implement a constructor that wasn't declared.

void LibarayBook::setAcc_num[](int acc[])
Illegal function name - you can't have [] in a function name. Same goes for all the other functions like that.

[FONT=monospace]
[/FONT]return acc_num[]; 
[] not needed.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users