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.

1 Answer

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;

}

void putdata()

{

cout<<"\n\t\t Name ::"<<name;

cout<<"\n\t\t Per ::"<<per;

}

};

void main()

{

student S("Sachin",78.00);

clrscr();

S.putdata();

getch();

}


Related questions

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 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 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 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 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 : 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 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 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 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 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 ‘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 ‘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 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 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 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 : 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 : 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 : 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 : 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 concept of overloaded constructor in a class with suitable example.

Last Answer : Overloaded constructor: When more than one constructor function is defined in a same class then it is called as overloaded constructor. All constructors are defined with the same name as ... first constructor does not accept any argument and the second constructor accepts two integer arguments.

Description : Explain constructor in derived class with suitable example.

Last Answer : When a class is declared, a constructor can be declared inside the class to initialize data members. When a base class contains a constructor with one or more arguments then it is ... one argument. Derived class constructor accepts two values and passes one value to base class constructor.

Description : Write any four characteristics of constructor.

Last Answer : The constructor functions have some special characteristics. They should be declared in the public section. They are invoked automatically when the objects are created. They do not have return types ... They make 'implicit calls' to the operators new and delete when memory allocation is required.

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 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 : What is copy constructor? Explain with example.

Last Answer : Copy constructor: The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to: ... ; // Copy constructor is called here // Let us access values assigned by constructors cout

Description : What is parametrized constructor? Explain with example.

Last Answer : A constructor that can take arguments is known as parameterized constructor. In some applications, it may be necessary to initialize the various data members of different objects with different values when they ... object is created. Member function put displays the value of data member m . 

Description : What do you mean by overloaded constructor?

Last Answer : When more than one constructor function is defined in a class, it is referred as overloaded constructor. Each overloaded constructor function is invoked with respect to arguments pass in the function call.

Description : Describe multiple constructor by giving example.

Last Answer : Multiple constructor: Multiple constructors is a category of constructor in which a class can have more than one constructor. This is also known as constructor overloading. All constructors are defined with the same name as the class ... constructor 1 integer(int a, int b) { m = a; n = b; cout

Description : How do we invoke a constructor function?

Last Answer : A constructor is invoked automatically when an object of its class is created. Example: class ABC { public: ABC( ) { } }; void main( ) { ABC obj; } In the above example, creating „obj‟ object automatically invokes constructor ‟ABC ( )‟.

Description : What is the importance of constructor?

Last Answer : A constructor is important to initialize the objects of its class. It is called constructor because it constructs the value of the data members inside object of the class.

Description : Describe constructor with syntax and example.

Last Answer : A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever an object of its associated class ... )//constructor declaration { a=0; } }; void main() { ABC x; }

Description : Define constructor. State any two types of constructor.

Last Answer : Definition: A constructor is a special member function whose task is to initialize the objects of its class. Types of constructor: 1) Default constructor 2) Parameterized constructor 3) Copy Constructor 4) Constructor with default value 5) Multiple constructor/overloaded constructor

Description : What is copy constructor? 

Last Answer : Copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to: Initialize one object from ... pass it as an argument to a function. Copy an object to return it from a function.

Description : Differentiate between constructor and destructor. 

Last Answer : Differentiate between constructor and destructor.

Description : Describe the concept of constructor with default argument with suitable example.

Last Answer : Definition: The constructor where we can assign default values for one or more parameters at the time of function declaration is called as constructor with default argument Example: class complex ... and 3.0 to img., because the actual parameters, when specified overrides the default value.

Description : State any four types of constructor.

Last Answer : Types of constructor: Default constructor Parameterized Constructor Constructor with Default Argument Copy Constructor Multiple/overloaded constructor

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 : Give a method to create, declare and initialize structure also develop a program to demonstrate nested structure.

Last Answer : Declaration of structure:- struct structure_name { data_type member 1; data_type member 2; . . . data_type member n; } structure variable 1, structure variable 2,..., structure variable n ... .collegeid); printf("\n College name=%s",s.c.collegename); 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 : Write down characteristics of object oriented programming.

Last Answer : Characteristics of object oriented programming are: Emphasis is on data rather than procedure. Programs are divided into objects. Data structures are designed such that they characterize the ... can be easily added whenever necessary. Follows bottom-up approach in program designing. 

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