Write a program to declare a class ‘book’ containing data members as ‘title’, ‘author-name’, ‘publication’, ‘price’. Accept and display the information for one object using pointer to that object.

1 Answer

Answer :

#include<iostream.h>

#include<conio.h>

class book

{

char author_name[20];

char title[20];

char publication[20];

float price;

public:

void Accept();

void Display();

};

void book::Accept()

{

cout<<"\n Enter book‟s title, author_name, publication and price \n:";

cin>> title >>author_name>> publication >> price;

}

void student::Display()

{

cout<<title <<”\t”<<author_name<<”\t”<<publication <<”\t”<<

price<<”\n”<<;

}

void main()

{

book b, *p;

clrscr();

p=&b;

p->Accept();

cout<<”title \t author_name \t publication \t price\n”;

p-> Display();

getch();

}


Related questions

Description : Implement a program to declare a class city with data members city name and state. Accept and display data for 1 object using pointer to object.

Last Answer : #include<iostream.h> #include<conio.h> class city { char city_name[20],state[20]; public: void accept() { cout<<"\nEnter city data:"; cout<<"\nName:"; ... ); ptr=&c; ptr->accept(); ptr->display(); getch(); }

Description : Write a program to declare class student having data members name and percentage. Write constructor to initialize these data members. Accept and display this data for one object.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class student { char name[20]; float per; public: student(char n[],float p) { strcpy(name,n); per=p; } ... { student S("Sachin",78.00); clrscr(); S.putdata(); getch(); }

Description : Write a program in C++ to declare a class „Journal‟ having data members as journal_nm, price, ISSN_No. Accept this data for two objects and display the name of the journal having greater price.

Last Answer : #include<iostream.h> #include<conio.h> class Journal { char journal_nm[20]; int ISSN_No; float price; public: void accept(); void display(Journal); }; void Journal::accept() { ... clrscr(); j1.accept(); j2.accept(); j1.display(j2); getch(); }

Description : Write a C++ program to declare a class COLLEGE with members as college code. Derive a new class as STUDENT with members as studid. Accept and display details of student along with college for one object of student.

Last Answer : #include<iostream.h> #include<conio.h> class COLLEGE { protected: int collegecode; }; class STUDENT:public COLLEGE { int studid; public: void accept() { cout<<"Enter college ... STUDENT s; clrscr(); s.accept(); s.display(); getch(); }

Description : Write a C++ program to declare a class ‘Account’ with data members as accno, name and bal. Accept data for eight accounts and display details of accounts having balance less than 10,000.

Last Answer : #include<iostream.h> #include<conio.h> class Account  { long int accno, bal; char name[10]; public: void getdata() { cout<<"\nEnter account number, balance and name "; cin>> ... 0;i<8;i++)  { a[i].putdata();  } getch();  }

Description : Write a C++ program to declare a class ‘circle’ with data members as radius and area. Declare a function getdata to accept radius and putdata to calculate and display area of circle.

Last Answer : #include<iostream.h> #include<conio.h> class circle { float radius,area; public: void getdata() { cout<<"Enter radius:"; cin>>radius; } void putdata() { area=3 ... { circle c; clrscr(); c.getdata(); c.putdata(); getch(); }

Description : Write a C++ program to declare a class ‘College’ with data members as name and college code. Derive a new class ‘student’ from the class college with data members as sname and roll no. Accept and display details of one student with college data.

Last Answer : #include<iostream.h> #include<conio.h> class college { char name[10]; int collegecode; public: void getcollege() { cout<<"Enter college name:"; cin>>name; cout< ... (); s.getstudent(); s.putcollege(); s.putstudent(); getch(); }

Description : Write a program to declare a class 'staff' having data members as name and department. Accept this data for 10 staffs and display names of staff that are in 'CO' department.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class staff {  char name[10], dept[10];  public:  void accept() { cout<<"Enter Name and Department:\t"; cin>> ... i=0;i<=10;i++) { s[i].display(); } getch(); }

Description : Write a program to declare class having data member as hrs, mins, secs. Write constructor to assign values and destructor to destroy values. Accept & display data for one object.

Last Answer : #include<iostream.h> #include<conio.h> class time { private: int hrs, mins,sec; public: time(int h,int m,int s) { hrs=h; mins=m; sec=s; } ~time() { cout<< hours ... } }; void main() { time t(2,43,56); t.display(); getch(); }

Description : Write a C++ program to declare a structure employee with members as empid and empname. Accept and display data for one employee using structure variable. 

Last Answer : #include<iostream.h> #include<conio.h> struct employee  { int empid; char empname[10];  }; void main()  { employee e; clrscr(); cout<<"\nEnter employee id ... empid; cout<<"\nThe Employee Name is "<<e.empname; getch();  }

Description : Write a C++ program to declare a class student with members as roll no, name and department. Declare a parameterized constructor with default value for department as ‘CO’ to initialize members of object. Initialize and display data for two students.

Last Answer : write a C plus plus program to declare a class which accept and display student information such as roll number division and percentage use get data and put data with required parameters

Description : Write a C++ program to declare a class addition with data members as x and y. Initialize values of x and y with constructor. Calculate addition and display it using function ‘display’.

Last Answer : #include<iostream.h> #include<conio.h> class addition { int x,y; public: addition(int,int); void display(); }; addition::addition (int x1,int y1) { x=x1; y=y1; } void addition: ... y); } void main() { addition a(3,4); a.display(); getch(); }

Description : Write a program in C++ to declare a class measure having data members as add 1, add 2, add 3. Initialize the values of two data members using constructor and display their addition using function.

Last Answer : #include<iostream.h> #include<conio.h> class measure { public: int add1,add2,add3; measure(int a,int b) { add1=a; add2=b; } void cal() { add3=add1+add2; } void display() ... ;>a>>b; measure m1(a, b); m1.cal(); m1.display(); getch(); }

Description : Write a program to implement single inheritance. Declare base class employee with Emp_No. and Emp_Name. Declare derived class fitness with height and weight. Accept and display data for one employee.

Last Answer : #include<iostream.h> #include<conio.h> class employee { protected: int emp_no; char emp_name[10]; public: void gete() { cout<< enter employee details ; cin>>emp_no; cin>> ... f.gete(); f.pute(); f.getft(); f.putft(); getch(); }

Description : Write a program to declare structure employee having data member name, age, street and city. Accept data for two employees and display it.

Last Answer : #include<stdio.h> #include<conio.h> struct employee { char name[10],street[10],city[10]; int age; }; void main() { int i; struct employee e[2]; clrscr(); for(i=0;i<2 ... =%s",e[i].street); printf("\n City=%s",e[i].city); } getch(); }

Description : Write a program in C++ to accept a string from a user and display its reverse using pointer.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> void main() { char str[20],*ptr; int l; clrscr(); cout<<"\n Enter a string : "; cin>>str; l=strlen(str); ... (l!=0) { ptr--; cout<<*ptr; l--; } getch(); }

Description : Write a program to implement the concept of virtual base class for following figure. Accept and display information of one employee with his name, code, basic pay, experience and gross salary with the object of employee class.

Last Answer : #include<iostream.h> #include<conio.h> class Master  {  char name[10],code[3];  public:  void acceptM() { cout<<"\nEnter name and code "; cin>>name>>code; ... .displayM(); e.displayA(); e.displayD(); e.displayE(); getch();  }

Description : Define a class student with int id and string name as data members and a method void SetData ( ). Accept and display the data for five students.

Last Answer : import java.io.*; class student { int id; String name; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); void SetData() { try { System.out.println("enter id and name for student"); ... (String are[]) {  student[] arr;  arr = new student[5];  int i;  for(i=0;i

Description : Write a program to Print values of variables and their addresses. Note : 1) Variables can be of any data type. 2)Use of & or pointer to display address shall be considered. 

Last Answer : #include #include void main() { int a,b; clrscr(); a=5; b=10; printf("\n Value of a=%d",a); printf("\n Address of a=%u",&a); printf("\n Value of b=%d",b); printf("\n Address of b=%u",&b); getch(); }

Description : Write a program to accept two numbers from user and perform addition, subtraction, multiplication and division operations using pointer.

Last Answer : #include #include void main() { int no1,no2,*ptr1,*ptr2,result; clrscr(); printf("Enter no1:"); scanf("%d",&no1); printf("\nEnter no2:"); scanf("%d",&no2); ptr1=&no1; ptr2=&no2; ... "\n Multiplication=%d",result); result=*ptr1/(*ptr2); printf("\n Division=%d",result); getch(); }

Description : Describe ‘this’ pointer with an example.

Last Answer : this' pointer:  C++ uses a unique keyword called this to represent an object that invokes a member function. This unique pointer is automatically passed to a member function when it is invoked. ... pointer is used to represent object s when setdata ( ) and putdata ( ) functions are called. 

Description : Accept data for five students and display it. Write a C++ program to displya sum of array elements of array size n. 

Last Answer : #include<iostream.h> #include<conio.h> void main() { int arr[20],i,n,sum=0; clrscr(); cout<<"\nEnter size of an array:"; cin>>n; cout<<"\nEnter ... ; } cout<<"\nSum of array elements is:"<<sum; getch(); }

Description : Write a program to implement the following hierarchy using suitable member functions. Refer Figure No.2.

Last Answer : # include <iostream.h> #include<conio.h> class Student { int roll_no; char name[10]; public: void read_studentData() { cout<< Enter student s roll no and name \n ; cin> ... { result r; clrscr(); r.read_result(); r.display_result(); getch(); }

Description : Write the applications of object oriented programming.

Last Answer : Applications of object oriented programming are: 1) Real time systems 2) Simulation and modeling 3) Object-oriented databases 4) Hypertext, hypermedia and expertext 5) AI and expert systems ... and parallel programming 7) Decision support and office automation systems 8) CIM/CAM/CAD systems

Description : An article is not eligible for concessional rates of Postal tariff under printed books if it contain a) Any book packet containing printed books without advertisement b) Any printed ... & inscription reproduced by mean of printing. d) Books containing wholly or substantially reading matter

Last Answer : b) Any printed publication published at regular interval

Description : Write a C++ program to accept array of five elements, find and display smallest number from an array.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[5],smallest,i; clrscr(); cout<<" Enter array elements:"; for(i=0;i<5;i++) cin>>a[i] ... } } cout<<endl<<"Smallest number="<<smallest; getch(); }

Description : Write a program to accept marks of four subjects as input from user. Calculate and display total and percentage marks of student. 

Last Answer : #include<stdio.h> #include<conio.h> void main() { float marks[4]; float total=0.0, perc=0.0; int i; clrscr(); for(i=1;i<=4;i++) { printf("Enter marks of ... is :%f",total); perc=total/4; printf("Percentage is %f",perc); getch(); }

Description : Write a program that copies contents of one file into another file.

Last Answer : Assuming input file to be copied file1.txt contents are “Hello Friends…” and file where the contents need to copy is file2.txt already created  #include #include #include #include #include void main() { clrscr(); ifstream fs; ofstream ft; char ch, fname1[20], fname2[20]; cout

Description : Write a program to overload the ‘—’ unary operator to negate the values.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class Number { int x,y; public: Number (int a, int b) { a =x; b =y; } void display() { cout<< ... ; -N1; cout<<"\n After negation:"; N1. display (); getch (); }

Description : Write a program to count the number of lines in file.

Last Answer : #include<iostream.h> #include<fstream.h> #include<conio.h> void main() { ifstream file; char ch; int n=0; clrscr(); file.open("abc.txt"); while(file) { file. ... \n Number of lines in a file are:"<<n; file.close(); getch(); }

Description : Write a program to sort an 1-d array in ascending order.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int arr[20]; int i, j, temp,n; clrscr(); cout<<"\n Enter the array size:"; cin>>n; cout<<"\n Enter ... 0;i<n;i++) {  cout<< \n <<arr[i]; } getch(); }

Description : Write a program to implement single inheritance from the following Refer Figure No.1

Last Answer : #include #include class employee { protected: int emp_id; char name[10]; }; class emp_info:public employee { int basic_salary; public: void getdata() { coutemp_id; coutname; coutbasic_salary; } void putdata() { cout

Description : A CPA in public accounting is prohibited from performing which of the following actions? a. Permit the publication of his being the author of a book. b. Be a party to a stratagem which permits a non ... his wife to acquire shares in a corporation's capital stock. d. Act as a stock and transfer agent

Last Answer : Be a party to a stratagem which permits a non-CPA to practice accountancy

Description : State the syntax to declare pointer variable with example.

Last Answer : General syntax to declare pointer. datatype *var_name; Eg: int var = 20;

Description : Write a shell script to accept length and breadth of rectangle from user. Calculate and display area, perimeter, of entered values using choice entered by user.

Last Answer : #!/bin/bash # GNU bash, version 4.3.46 echo "Enter Length of Rectangle: " read length echo "Enter Breadth of Rectangle: " read breadth echo "Which operation you want to perform? 1: area 2: perimeter" read ... ) res=` echo 2 \* $length \* $breadth | bc` ;; esac echo "Result is $res" exit 0

Description : When the RET instruction at the end of subroutine is executed, a. the information where the stack is iniatialized is transferred to the stack pointer b. the memory address of the RET instruction is ... two data bytes stored in the top two locations of the stack are transferred to the stack pointer

Last Answer : c. two data bytes stored in the top two locations of the stack are transferred to the program counter

Description : State and describe access specifiers used inside class to declare members.

Last Answer : Access specifiers: 1. private 2. protected 3. public Private access specifier: Class members declared as private can be accessed only from within the class. Outside class access is not allowed for private members of ... { private: int a; protected: int b; public: void display() { cout

Description : What is multilevel inheritance? Draw the diagram to show multilevel inheritance. using classes with data member and member function. 

Last Answer : When a class is derived from another derived class then it is called as multilevel inheritance.

Description : Define a class circle having data members pi and radius. Initialize and display values of data members also calculate area of circle and display it.

Last Answer : class abc {  float pi,radius; abc(float p, float r) { pi=p; radius=r; } void area() { float ar=pi*radius*radius; System.out.println("Area="+ar); } void display() { System.out.println("Pi="+pi ... void main(String args[]) { abc a=new abc(3.14f,5.0f); a.display(); a.area(); } }

Description : Write a program which concate and reverse string by using pointer to string.

Last Answer : #include #include void main()  { char str1[20], str2[20], rev[20],*p1,*p2; int cnt=0; clrscr(); coutstr2;  p1=&str1[0];  p2=&str2[0]; while(*p1!='\0')  { p1++;  } while(*p2!='\0')  { *p1=*p2; p1++; p2++;  }  *p1='\0'; cout

Description : Write a program which perform arithmetic operation using pointer.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int num[5]={56,75,22,18,90}; int ptr; int i; cout<< array elements are:: ; for(i=0;i<5;i++) ptr=num; cout<< ... 3; cout<< value of ptr+=3:: <<*ptr; cout<< \n ; getch(); }

Description : Write a program to copy content of one string to another string using pointer to string.

Last Answer : #include<iostream.h> #include<conio.h> void main() { char str1[10],str2[10],*p1,*p2; clrscr(); cout<<"\n Enter a String"; cin>>str1; p1=&str1[0]; p2= ... } *p2='\0'; cout<<"Copied String is "<<str2; getch(); }

Description : Write a program to find length of a string using pointer to string.

Last Answer : #include<iostream.h> #include<conio.h> void main() { char str1[10],*ptr; int len=0; cout<<"enter string:"; cin>>str1; ptr=&str1[0]; while(*ptr!='\0 ... +; } cout<<"\nThe Length of a string is"<<len; getch(); }

Description : Write a program to search a number from an array using pointer to array.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[5],i,*a1,no,flag=1; clrscr(); a1=&a[0]; cout<<"\nEnter array elements :"<<endl; for(i=0;i<5 ... =0) { cout<<"\n\t Number is not present.... "; } getch(); }

Description : Write a program in C++ to search an element from an array using pointer.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[10], n, i,*p, flag=0, x; clrscr(); cout<<"Enter no. of array elements \n"; cin>>n; cout<< ... } if(flag==0) cout<<x<<"is not found \n"; getch(); }

Description : Write a C++ program to create a class STUDENT The data members of STUDENT class. Roll_No Name Marks

Last Answer : #include #include class STUDENT { int Roll_No; char Name[20]; float Marks; }; OR #include #include class STUDENT { int Roll_No; char Name[20]; float Marks; public: void Accept(); void Display(); }; void STUDENT::Accept() { cout

Description : Develop a program using structure to print data of three students having data members name, class, percentage.

Last Answer : #include #include void main() { struct student { char name[20]; char c[20]; int per; } s[3]; int i; clrscr(); for(i=0;i

Description : Explain virtual base class with suitable example.

Last Answer : Consider a situation where all three kinds of inheritance, namely, multilevel, multiple, hierarchical inheritance, are involved. This illustrated in fig a. the child has two direct base classes, parent1 & ... Grandparent { }; class Child: public Parent1,public Parent2 { };

Description : What is a class? Give its example. 

Last Answer : Class is a user defined data type that combines data and functions together. It is a collection of objects of similar type. Example: class Student { int rollno; char name[10]; public: void getdata( ); void putdata( ); };

Description : Implement single inheritance for following fig. Accept and display data for 1 table.

Last Answer : #include class furniture { protected: char material[20]; int price; }; class table :public furniture { int height ; float sur_area; public: void getdata() { coutmaterial; coutprice; coutheight; coutsur_area; } void putdata() { cout