Question

In: Computer Science

1) Within the main function, the call to the constructor by defense of a class called...

1) Within the main function, the call to the constructor by defense of a class called MyClass is made by creating the firstClass object as follows.

A) MyClass firstClass;

B) MyClass firstClass (8);

C) MyClass () firstClass;

D) MyClass firstClass ();

Solutions

Expert Solution

A) MyClass firstClass;

// Screenshot of the code

// Sample output

// Code to copy

#include<iostream>

using namespace std;

class MyClass{  
   public:
       MyClass(){      
           cout<<"Constructor ";
       }
};
int main(){
   MyClass firstClass;  
   return 0;
}

B) MyClass firstClass (8);

// Screenshot of the code

// Sample output

// Code to copy

#include<iostream>
using namespace std;
class MyClass{
   private:
       int n;
   public:
       MyClass(int n){
           n=n;
           cout<<"Constructor "<<n;
       }
};
int main(){
   MyClass firstClass (8);  
   return 0;
}

D) MyClass firstClass ();

// Screenshot of the code & output

// Code to copy

#include<iostream>
using namespace std;
class MyClass{
   public:
       MyClass(){
           cout<<"Constructor";
       }
};
int main(){
   MyClass firstClass ();  
   return 0;
}


Related Solutions

In C Write a main function with a function call to a function called GetLetter which...
In C Write a main function with a function call to a function called GetLetter which has two double arguments/parameters. The function returns a character. Declare and initialize the necessary data variables and assign values needed to make it executable and to prevent a loss of information
1. A constructor is a special Class member method. It is automatically called when an object...
1. A constructor is a special Class member method. It is automatically called when an object of the class is created. It can also be called more than once after the object is created. 2. In Java, the new operator is used to create an instance/object of a class in the heap. 3. A reference variable is a memory location contains an address of an object stored in the stack. 4. Encapsulation and abstraction are both the pillars of Object-Oriented...
in java Create a class called Customer in three steps: • (Step-1): • Add a constructor...
in java Create a class called Customer in three steps: • (Step-1): • Add a constructor of the class Customer that takes the name and purchase amount of the customer as inputs. • Write getter methods getName and getPrice to return the name and price of the customer. You can write a toString() method which returns printed string of Customer name and its purchase. • (Step-2): Create a class called Restaurant. • Write a method addsale that takes customer name...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
you will find a class called Employee. This class should include a constructor that sets name...
you will find a class called Employee. This class should include a constructor that sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will create a...
You will be writing the function definition and the main function with the function call. Be...
You will be writing the function definition and the main function with the function call. Be sure to write the function definition below the main function. The function prototype has been provided, you may add the prototype to you answer. You do not need to add the preprocessor directives like #include<stdio.h>. Write the function definition for UpdateGrade . The function will take two arguments, a double called originalGrade a pointer to a double called newGradePtr. This function will have a...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT