You are on page 1of 1

Sample question for Quiz-1

Be informed that this is just a sample, not necessarily the pattern of the actual question

Consider the following main(). You need to write the FULL CLASS along with necessary member data and member
functions. You also need to write global functions, if any. Your program should be able to execute the given main().

class Computer{
//data: manufacturerName, speedInGigaHartz, ramInGB;
public:
//write default constructor
//write parameterized constructor
//add other necessary member functions...
//declare necessary friend functions...
};

//need to overload >> operator allowing function chaining


//Should ask ramInGb, speedInGigaHartz and manufacturerName

//need to overload << operator allowing function chaining


//Should print ramInGb, speedInGigaHartz and manufacturerName
// the operator function should not print default info if not initialized

int main(){
Computer *ptr; //represent an array of Computer objects
int n; //no of computers

populateComputers(ptr, n, rand()%n);
//write this global function
// this function allocates memory for n Computer objects to ptr and default
// constructor is automatically fired for them. Now you have to overwrite
// the default values of first m no of computers (m is 3rd parameter)
// by using cin>>ComputerObject format in a loop.

cout << “Detail of the computers having input-ed info are: “ << endl;
for(i=0; i<n ;i++) cout << ptr[i] << endl;
// the operator function should not print default info if not initialized

Computer c1(“Lenovo”, 2.5, 4), c2(“Apple”, 3.0, 8), c3, c4;


cout << ”Enter details of c3 & c4: “ << endl; cin >> c3 >> c4;
int totalRam = c1 + c2 + c3.returnRam() + c4;
//need to overload ‘+’ operator twice. ‘+’ means adding Rams, not Computers
cout << ”Total Ram of all 4 computers is: “<<totalRam<<” GB”<< endl;

bool flag = true;


if (flag == (c1==c2) && flag == (c2==c3) && flag == (c3==c4))
cout<<”Processor speed of all computers are equal.”<<endl;
else cout<<”Processor speed of all computers are NOT equal.”<<endl;
return 0;
}

You might also like