Program C++ (use visual studio)
Q1. What default copy constructor does the compiler insert in the following class?
class Student {
string name;
string id;
double grade;
};
===========================
Q2 .What is the factor transfer method used when the f() function is called from?
void f(int n[]);
int main() {
int m[3]= {1, 2, 3};
f(m);
}
==================================
Q3. Write a program that produces a bigger() with a prototype as shown below and outputs a large value by inputting two integers from the user. Bigger() returns true or false if a given factor is equal to a, b, and passes the large number to big.
[ bool bigger(int a, int b, int& big); ]
program code:
Q.no.1:
The default copy constructor the compiler insert in the given Student class is
Student( Student &N) { Name = N.Name ; id = N.id ; grade = N.grade ; }
//Where Student is the default copy constructor function name
//The Student inside the parenthesis is an object of the Student class and it stores the address of a N variable of type Student.
//The attributes of N are assigned to the Student class data members
Q.no.2:
//In the given program
void f(int n[]);
int main() {
int m[3]= {1, 2, 3};
f(m);
}
//The function void f(int n[]); is not defined and it does not include the proper arguments to define the factor transfer method.
//The function void f(int n[]); only gets a copy of the m[3] integer array defined in main function
Q.no.3:
#include<iostream>
using namespace std;
//function prototype
bool bigger(int a, int b, int big);
int main() {
//Factor to be compared
int big = 10;
int a,b;
cout <<"Enter the 1st integer :\n";
cin >> a;
cout <<"Enter the 2nd integer :\n";
cin >>b;
cout <<"\n";
cout << bigger( a, b, big);
return 0;
}
bool bigger(int a, int b, int big) {
// Function returns true or false by comparing two numbers entered
by user
if (a > b) {
if(big > a) {
return true;
}
else {
big = a;
return false;
}
}
if (a < b) {
if(big > b) {
return true;
}
else {
big = b;
return false;
}
}
}
// 0 means False condition
// 1 means True condition
Comment down for any queries
Please give a thumbs up
Get Answers For Free
Most questions answered within 1 hours.