Comments

Thursday, November 8, 2012

OOP Object of the Book copy string to other string in class

Posted by at 9:47 AM Read our previous post
Object
Create an object for the book which ask user to input about author,number of pages, quality of book,type of book,and Title of the book.

Source code:
#include <iostream>
#include <stdio.h>
using namespace std;
#include <string>
class book
{
private:
    char bookname[50],writer[50],topic[20],type[10],addchapter[250];
    int pageno,quality,chapters;
public:
    void setdata(char bbookname[50],char bwriter[50],char btopic[20],char btype[10],char baddchapter[250],
    int bpageno,int bquality,int bchapters)
    {
        strcpy (bookname,bbookname);
        strcpy (writer,bwriter);
        strcpy (topic,btopic);
        strcpy (type,btype);
        strcpy (addchapter,baddchapter);
   
    int pageno=bpageno,
        quality=bquality,
        chapters=bchapters;
    }

    void showdata()
    {
    cout<<"Book Name:"<<bookname<<endl;
    cout<<"Book writer:"<<writer<<endl;
    cout<<"Book topic"<<topic<<endl;
    cout<<"Book type"<<type<<endl;
    cout<<"Book addchapter"<<addchapter<<endl;
    }
};
void main()
{
   
    book bk[10];
    char bookname[50],writer[50],topic[20],type[10],addchapter[250];
    int pageno,quality,chapters;
    char press;
    int num=0,no;
do{
    cout<<"Enter Book Name: "<<endl;
    cin.getline(bookname,50);
    

    cout<<"Enter Book writer: "<<endl;
    cin>>writer[50];
    

    cout<<"Enter topic of Book: "<<endl;
    fflush(stdin);
    cin.getline(topic,20);
    

     cout<<"Enter type of Book: "<<endl;
     fflush(stdin);
     cin.getline(type,10);
   

    cout<<"Enter Add Chapter: "<<endl;
    fflush(stdin);
     cin.getline(addchapter,250);
   

    cout<<"Enter Page no:"<<endl;
    cin>>pageno;

    cout<<"Enter Quality of Book:"<<endl;
    cin>>quality;

    cout<<"Enter no of Chapter"<<endl;
    cin>>chapters;

    bk[num].setdata( bookname,writer,topic,type,addchapter,
                pageno,quality,chapters);
    cout<<"Press y to continue"<<endl;
    num++;
    }
    while(press=='y');
    cout<<"View Book number"<<endl;
    cin>>no;
   
    bk[no].showdata();
}


Output

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template