Q1. Create a class on an object Computer with two fields and two methods as follows: (5 points)
field: cpu and memory, method: compile( ) and execute( )
Q2. Write a source code to activate a class created in Q1. (5 points)
check out the solution and do COMMENT if any doubts
--------------------------------------------------------------------
#include <iostream>
using namespace std;
// class computer
class Computer {
// 2 fields
public:
float cpu;
float memory;
// 2 methods
public:
void compile() {
// implement the methods as required
cout << "\nMemory gets allocated to the program at compile
time";
}
void execute() {
cout << "\nCPU executes the number of intructions present in
program while execution of the program";
}
}; // class ends
// source code - main method
int main() {
// activates the class by creating an object of that class
Computer computer;
// demonstration of access to class variables using the
object
computer.cpu = 12.5;
computer.memory = 25;
cout << "CPU time : " << computer.cpu <<
endl;
cout << "Memory used : " << computer.memory <<
endl;
// demonstration of class methods using object
// call the methods of the class using objects
computer.compile();
computer.execute();
} // main method ends
-------------------------------------------------------------------
------------------------
OUTPUT ::
Get Answers For Free
Most questions answered within 1 hours.