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.

1 Answer

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()

{

cout<<"\n Enter journal's data:";

cout<<"\n Name:";

cin>>journal_nm;

cout<<"\n ISSN No:";

cin>>ISSN_No;

cout<<"\n Price:";

cin>>price;

}

void Journal::display(Journal j2)

{

if(price>j2.price)

{

cout<<"\n Data of journal having greater price is:";

cout<<"\n Name:"<<journal_nm;

cout<<"\nISSN No="<<ISSN_No;

cout<<"\n Price="<<price;

}

else

{

cout<<"\n Data of journal having greater price is:";

cout<<"\n Name:"<<j2.journal_nm;

cout<<"\n ISSN No="<<j2.ISSN_No;

cout<<"\n Price="<<j2.price;

}

}

void main()

{

Journal j1,j2;

clrscr();

j1.accept();

j2.accept();

j1.display(j2);

getch();

}


Related questions

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 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 : 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 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 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.

Last 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 ... title \t author_name \t publication \t price\n ; p-> 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 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 : 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 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 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 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 : 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 : 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

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 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 : What is structure? How user declare structure? Give example.

Last Answer : Structure is a collection of different data types written under a common name. It is a user defined data type. To Define a structure following Syntax is use:- struct structure_name { data_type variable 1; data_type ... () {  Person p1; cout>p1.name; cout> p1.age; cout> p1.salary; cout

Description : Write a program in C++ to implement following inheritance. Assume suitable data.

Last Answer : #include<iostream.h> #include<conio.h> class employee { int empid; char empname[20]; public: void accept() { cout<<"\n enter empid, empname:"<<endl; cin>>empid>> ... m.acc1(); m.dis1(); w.acc2(); w.dis2(); getch(); }

Description : What are objects? How are they created?

Last Answer : Objects Objects are basic run time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle. An object is the ... object; OR class classname { class definition }; main() { classname object; }  

Description : Write a program to swap two integer values by using call by reference.

Last Answer : #include #include void swap(int *a,int *b) { int c; c=*a; *a=*b; *b=c; } void main() { int a,b; couta; coutb; cout

Description : Write a program to overload ‘+’ operator to concatenate two strings.

Last Answer : #include #include #include class string1 { char str[20]; public: void getdata() { coutstr; } void display() { cout

Description : Write a C++ program to overload = = operator to check equality of two strings.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class string { char str1[20]; public: void get() { cout<<"Enter string:"; cin>>str1; } void operator = =( ... ; string s,s1; s.get(); s1.get(); s==s1; 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 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 which implement the concept of overloaded constructor.

Last Answer : #include #include class integer { int m,n; public: integer() { m=0; n=0; } //default constructor 1 integer(int a, int b) { m=a; n=b; } //Parameterized constructor 2 integer(integer &i) { m=i.m; n=i.n; } //copy constructor 3 }; void display() { cout

Description : Write a program to find whether the string is palindrome or not.

Last Answer : #include #include #include void main() { char str1[10],str2[10]; int c; clrscr(); coutstr1; strcpy(str2,str1); strrev(str2); cout

Description : Write a program for multiple inheritance. 

Last Answer : #include #include class base1 { public: void show1() { cout

Description : Write a program to show object as function argument. 

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class objarg  { char str[10]; public: void get() { cout<<"\n Enter a Message"; cin>>str; } void ... clrscr(); o1.get(); o2.copy(o1); o2.display(); 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 for overloading of ++unary operator for inch to feet conversion. 12 inch = 1 feet.

Last Answer : #include #include class abc { int i,f; public: abc(int f1,int i1) { f=f1; i=i1; } void operator ++() {  while(i>11)  {  f++;  i=i-12;  }  cout

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 calculate area of circle and area of rectangle using function overloading. 

Last Answer : #include<iostream.h> #include<conio.h> float area(float a) { return (3.14*a*a); } int area(int p,int q) { return(p*q); } void main() { clrscr(); cout< ... ;<<area(6); cout<<"Area of Rectangle:"<<area(5,6); 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 using concept of pointers to string for performing following operations: (i) String concatenation (ii) String comparisons

Last Answer : (i) Program to implement String Concatenation: #include #include void main() { char s1[50],s2[30],*p,*q; clrscr(); couts1>>s2; p=s1; q=s2; while(*p!=NULL) { p++; } while(*q!=NULL) { *p=*q; p++; q++; } *p='\0'; cout

Description : Write a program to demonstrate the use of pure virtual function.

Last Answer : Consider the following example where parent class provides an interface to the base class to implement a function called getArea() as pure virtual function: #include // Base class class Shape { protected: int ... ; Rect.setWidth(5); Rect.setHeight(7); // Print the area of the object. cout

Description : Write a program in C++ to implement single inheritance from following figure:

Last Answer : #include<iostream.h> #include<conio.h> class product { protected: int prodid; char prodname[20]; }; class edible:public product { char flavour[20]; public: void accept() { cout<< ... for(i=0;i<5;i++) { e[i].display(); } getch(); }

Description : Write a program in C++ to overload a „volume‟ function to calculate volume of cube and rectangular box. 

Last Answer : #include<iostream.h> #include<conio.h> void volume(float); void volume(float, float, float); void main() { float a, length, width, height; clrscr(); cout<<"\n ... width*height; cout<<"\n Volume of a rectangular box is:"<<v; }

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 : State characteristic of static data member. Explain why static data member must be defined outside the class. 

Last Answer : Characteristics of static data members: 1. It is initialized to zero when the first object of its class is created. No other initialization is permitted. 2. Only one copy of that member is created ... member(s) it is necessary to make static members global and re-declared outside of the class.

Description : Define the following terms: (i) Data abstraction (ii) Class (iii) Dynamic binding (iv) Polymorphism

Last Answer : (i) Data abstraction: Abstraction refers to the act of representing essential features without including the background details or explanation. Data abstraction is the process of defining a data type, often ... more than one form at different instances depending on the type or number of arguments. 

Description : Describe structure of C++ program.

Last Answer : General C++ program has following structure. INCLUDE HEADER FILES DECLARE CLASS DEFINE MEMBER FUNCTIONS DEFINE MAIN FUNCTION Description:-  1. Include header files In this section ... Functions This section the programmer creates object and call various functions writer within various class.

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 : What is constructor? How user can declared constructor in derived class? Explain with example.

Last Answer : Constructor:- Constructor is a special member function which has same name as a class name and is used to initialize object during compile time of program. Declaring constructor in derived class If a base class contains a ... derived d(2,5); d.displaybase(); d.display(); getch(); }

Description : Explain the derived class access by pointer.

Last Answer : When base class and its derived class both contains same function name then the function in base class is declared as virtual using keyword virtual preceding its normal declaration. When a function is made virtual, C ... . Example: #include class Base { public: virtual void show( ) { cout

Description : What is base class? What is derived class? Give example.

Last Answer : Base class: In inheritance a new class is derived from an old class. The old/existing class is referred as base class whose properties can be inherited by its derived class. Derived class: In inheritance a new ... as well as base class. Example: class base { public: void putb() { cout

Description : What is abstract class? Give one example of abstract class.

Last Answer : An abstract class is a class that is designed only to act as base class. It is not used to create objects. An abstract class is used to define an implementation and is intended to be inherited by child classes. Example: ... >a; } void display() { coutb; } void display1()  { display(); cout