Question

In: Computer Science

IN C++, IN C++, IN C++ Write the A and B classes, the properties of which...

IN C++, IN C++, IN C++

Write the A and B classes, the properties of which will produce the expected output with the test code provided, and the characteristics of which are specified below. Note the types of pointers used in the test code.
Methods of class A:
- void hi () - Prints “Hi A” on the screen.
- void selam() - Prints "Selam A" on the screen.
Class B must inherit class A. Class methods should be written so that access levels can produce the desired output in the test code provided.

Test code:

int main() {
A* ptrA1 = new A{};
A* ptrB1 = new B{};
B* ptrB2 = new B{};
ptrA1->selam();
ptrA1->hi();
ptrB1->selam();
ptrB1->hi();
ptrB2->selam();
ptrB2->hi();
return 0;
}

Expected output:

Selam A
Hi A
Selam A
Hi B
Selam B
Hi B

Solutions

Expert Solution

//C++ CODE TO COPY//

//precompiled used headers
#include<iostream>
using namespace std;

//parent class A
class A
{
   //class functions

   //public virtual function hi()
public:
   virtual void hi()
   {
       cout << "\nHi A";
   }

   //public function selam()
   void selam()
   {
       cout << "\nSelam A";
   }
};

//Derived class B inherited fronm A
class B : public A
{
   //public functions
public:
   void hi()
   {
       cout << "\nHi B";
   }

   void selam()
   {
       cout << "\nSelam B";
   }
};

//main() test function
int main()
{
   A* ptrA1 = new A{};
   A* ptrB1 = new B{};
   B* ptrB2 = new B{};

   ptrA1->selam();
   ptrA1->hi();
  
   ptrB1->selam();  
   ptrB1->hi();

   ptrB2->selam();
   ptrB2->hi();

   return 0;
}

  


//PROGRAM OUTPUT//

//COMMENT DOWN FOR ANY QUERIES...
//HIT A THUMBS UP IF YOU DO LIKE IT!!!


Related Solutions

IN C++, IN C++, IN C++, IN C++, IN C++ Write the A and B classes,...
IN C++, IN C++, IN C++, IN C++, IN C++ Write the A and B classes, the properties of which will produce the expected output with the test code provided, and the characteristics of which are specified below. Note the types of pointers used in the test code. Methods of class A: - void hi () - Prints “Hi A” on the screen. - void selam() - Prints "Selam A" on the screen. Class B must inherit class A. Class...
Not: The number of elements, attributes, classes, properties, and sub properties will be assessed comparing to...
Not: The number of elements, attributes, classes, properties, and sub properties will be assessed comparing to your respective domains (website) and not according to the respective numbers 40, 20,60,30,15: given for reference of level. 10 queries Task: Think and define the domain of your interest: Put the link of the website/ domain. Write XML document: Point out at least 40 terms (elements) in your domain Point out at least 20 attributes in your domain Define an XML schema by using...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files...
Objectives:  Write classes in C++  Use dynamic arrays  Write and read from files 1. WriteaclassGradeBookcontainingthefollowing: Private attributes: - courseName: a string representing the name of the course. - nbOfStudents: an integer representing the number of students enrolled in the course. The number of students is greater than or equal to 5. - grades: a double dimensional array of integers representing the grades of Test1, Test2 and Final of every student. It should be a dynamic array. Public...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a Singapore Airlines Loyalty program. You are asked to write an inheritance hierarchy discount system that benefits KrisFlyer members program to calculate their profit. A brief about KrisFlyer is that it is useful for those who fly on Singapore Airlines (its partners like Virgin Australia and Air New Zealand) frequently. KrisFlyer miles can be earned through credit cards, flying and bonus miles promotions. The miles...
Jones transfers contributed three properties, A, B and C, to Newco and that the FMV of...
Jones transfers contributed three properties, A, B and C, to Newco and that the FMV of each was $160,000, 55,000 and $35,000, respectively and the adjusted basis of each property was $140,000, $90,000 and $80,000, respectively. What are the tax consequences to Jones and Newco
C++ - When working on this assignment, focus on memorizing the syntax for writing classes. Write...
C++ - When working on this assignment, focus on memorizing the syntax for writing classes. Write a simple class named Circle, with three private variables: doubles named x, y and radius. The center of the circle is denoted by coordinates (x,y), and the radius of the circle is denoted by radius. It should have public member functions with the following signatures: void setRadius(double r) void setX(double value) void setY(double value) double getRadius() double getX() double getY() double getArea() bool containsPoint(double...
Write a C++ program that will be an information system for Oregon State University using classes...
Write a C++ program that will be an information system for Oregon State University using classes as well as demonstrating a basic understanding of inheritance and polymorphism. You will create a representation of an Oregon State University information system that will contain information about the university. The university will contain a name of the university, n number of buildings, and m number of people. People can be either a student or an instructor. Every person will have a name and...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
(6ptseach)Let A={a,b,c},B={b,c,d},C ={b,c,e}. (a) Explicitly find (i) A∪(B∩C), (ii)(A∪B)∩C, and (iii)(A∪B)∩(A∪C). (iv)Which of these sets are...
(6ptseach)Let A={a,b,c},B={b,c,d},C ={b,c,e}. (a) Explicitly find (i) A∪(B∩C), (ii)(A∪B)∩C, and (iii)(A∪B)∩(A∪C). (iv)Which of these sets are equal? (b) Explicitly find (i) A∩(B∪C), (ii)(A∩B)∪C, and (iii)(A∩B)∪(A∩C). (iv)Which of these sets are equal? (c) Explicitly find (i)(A−B)−C and (ii) A−(B−C). (iii)Are these sets equal?
Determine an A-B-C classification for these items: • Which items are A, B, and C -...
Determine an A-B-C classification for these items: • Which items are A, B, and C - explain how you derive the answers? Item   Unit Cost Annual volume(000) 1 300 25 2 90 30 3 30 60 4 50 10 5 15 70 6 100 40 7 10 60 Hint: Determine the Annual Dollar Value (Unit Cost * Annual Volume) for each item and the sum of the individual Annual Dollar Values. Arrange the items in descending order based on Annual...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT