100% found this document useful (1 vote)
17K views10 pages

C++ Important Questions With Answer

The document contains questions about C++ programming concepts and asks for explanations and code examples. Part A includes questions about writing programs to find the sum of natural numbers, differences between constructors and destructors, how objects are passed as arguments to functions, and differences between classes and structures. It also asks to write a program to swap two numbers. Part B asks to explain different types of constructors, describe object-oriented programming with an example, and provide a program to collect student information using an array of objects and calculate average marks.

Uploaded by

lakshi17504
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
17K views10 pages

C++ Important Questions With Answer

The document contains questions about C++ programming concepts and asks for explanations and code examples. Part A includes questions about writing programs to find the sum of natural numbers, differences between constructors and destructors, how objects are passed as arguments to functions, and differences between classes and structures. It also asks to write a program to swap two numbers. Part B asks to explain different types of constructors, describe object-oriented programming with an example, and provide a program to collect student information using an array of objects and calculate average marks.

Uploaded by

lakshi17504
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

IMPORTANT QUESTIONS

PART A
1. Write a C++ program to find the sum of n natural number.

ANS:

2. What are the difference between constructor and destructor.

ANS:
3. How are object passes as argument to a function.

ANS:

4. What are the difference between classes and structure.

ANS:
5. Write a C++ program to swap two numbers.

ANS:
PART b
1. Explain different types of constructor in C++

ANS:
2. Describe object-oriented programming concept with an example.

ANS:
3. Create a C++ program which collects student information and use the concept of an
array of objects to determine the average mark.
ANS:
#include <iostream>
using namespace std;
class student{
public:
char name[20];
int reg,in;
int mark1;
int mark2;
int mark3;
int getinput(){
cin>>name;
cin>>reg;
cin>>mark1>>mark2>>mark3;
}
int putinput(){
cout<<"the name is:"<<name;
cout<<"the reg number is:"<<reg;
cout<<"The average is:"<<(mark1+mark2+mark3)/3;
}
};
int main() {
student s1[100];
for(int i=0;i<=4;i++){
s1[i].getinput();
s1[i].putinput();
}
return 0;
}

You might also like