Question

Q1. Create a class on an object Computer with two fields and two methods as follows:...

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)

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(Please use java to write these questions) Q1. Create a class on an object Computer with...
(Please use java to write these questions) 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)
C++ Design a class named Computer that holds the make, model, and amount of memory of...
C++ Design a class named Computer that holds the make, model, and amount of memory of a computer. Include methods to set the values for each data field, and include a method that displays all the values for each field. Create the class diagram and write the pseudocode that defines the class. Pseudocode help please
Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for...
Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for all methods should print simple messages to the screen using System.out.println(). Add an integer speed variable that is changed using the ChangeSpeed method. ChangeSpeed adds 5 to the speed each time it is called. Create a default constructor that sets the initial speed to 0. Don't create other constructors or any setter/getter methods. PLEASE CODE THIS IN JAVA
Coding in Java Create an Airplane class (not abstract) that uses the Vehicle interface in Q1....
Coding in Java Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for all methods should print simple messages to the screen using System.out.println(). Add an integer speed variable that is changed using ChangeSpeed method. ChangeSpeed adds 5 to the speed each time it is called. Create a default constructor that sets the initial speed to 0. Don't create other constructors or any setter/getter methods. // code from Q1: interface Vehicle { void Start();...
Write an object oriented programming (JAVA) code. Create a class called Circle. The class has an...
Write an object oriented programming (JAVA) code. Create a class called Circle. The class has an attribute radius, which default to 1 by the first no-arg constructor. The class also has another constructor that instantiates the radius to a given value. Provide methods that calculate the circumference and the area of the circle (use Math.PI and Math.pow). Provide set and get methods. The set method should verify that radius is greater than or equal to 0.0 and less than 20.0,...
Write a class named Car that has the following fields: • yearModel: The yearModel field is...
Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values should...
1.Write a program that instantiates an object from the computer class and writes data into the...
1.Write a program that instantiates an object from the computer class and writes data into the object. you can set the data internally in the program. You do not need to ask for keyboard input. 2. Create a method that displays the data inside the computer object.
write code using python or repl.it 1. List 4 attributes that you'd create for class "student"....
write code using python or repl.it 1. List 4 attributes that you'd create for class "student". 2. List 2 setters and 2 getters for class student including their parameters 3. Write the complete definition for class student including attributes and methods created above using the correct Python syntax. 4. Create one object of class student and print the values of all its attributes. You can either call the getter method or access the attribute directly using the dot notation.
Define a class named Employee that has four data fields: name: String hoursWorked: double hourlyPayrate: double...
Define a class named Employee that has four data fields: name: String hoursWorked: double hourlyPayrate: double bonusRate: double The class has two constructors: 1. constructor without arguments: initialize name to empty string, and all other data fields to 0.0 2. constructor with a String type arguments and three double type arguments. Use them to initialize the data fields properly The class also has: 1. Getter method for each data field to return the value of the data field 2. Setter...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run it a second time after uncommenting the line obj.speak();. public class AnimalRunner {    public static void main(String[] args)    {       Dog d1 = new Dog("Fred");       d1.speak();       Object obj = new Dog("Connie");       // obj.speak();    } } The uncommented line causes a compile error because obj is an Object reference variable and class Object doesn’t contain a speak() method. This...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT