Home Activity Consider the class class base { public: virtual void iam) { cout << "base\n"; }; Derive two classes from class base, and for each define iam() to write out the a. name of the class. b. Declare objects of each class, and call iam) from them. c. iam() through the pointers. Assign the address of objects of the derived classes to base pointers and call d. Remove the virtual keyword from the base class member function, run your code again, and compare the results.
Q: Create a simple “shape” hierarchy: a base class called Shape and derived classes called Circle,…
A: The answer is..
Q: Write a program to read the GPA of students from users and display the details using dynamic memory…
A: arr will be dynamic and thus new keyword is specified to allocate memory of specified size
Q: Define the class Student which has the private members name, ID, GPA, numberOfCourses, marks] (one…
A: Student.h: #ifndef STUDENT_H_INCLUDED #define STUDENT_H_INCLUDED #include <iostream>…
Q: X-Functions of a class can be called with the _______ operator using the name of the object, or the…
A: Refer to step 2 for the answer.
Q: Create a class Number with a pointer as a data data member of integer type. Write user defined copy…
A: Required: Create a class Number with a pointer as a data data member of integer type. Write user…
Q: A class Student has Roll No, Branch, class Internal_exam has sub1marks, sub2 marks, class…
A: Given: A class Student has Roll No, Branch, class Internal_exam has sub1marks, sub2 marks, class…
Q: Create a class Number with a pointer as a data data member of integer type. Write user defined copy…
A: Given: Operation using Copy Constructor.
Q: Create a class Rectangle that has two data members, width and height, and two overloaded class…
A: If a class has many functions with the same names but different parameters, it is said to be…
Q: Write a program to create a base class: "Question3", with protected data member: x (int) and with…
A: Approach: - Include the header file and then use the namespace std.Define the class…
Q: using C++ 0OP Q1: Consider a class network of fig(1). The class Result derives information from two…
A: Your C++ program is given below as you required with an output.
Q: Question no 2: Consider the following details of all classes Person Employee Student Administration…
A: Solution: Given: To Find: To write the code for the following classes.
Q: uestion 1: a. Create a struct HeapItem as follows: template <typename k, typename v> struct…
A: A max-heap is a complete binary tree in which the value in each internal node is greater than or…
Q: Question3”, with protected data member: x (int) and with pure virtual function: “Task ()” [Returns…
A: #include <iostream>using namespace std; class Question3{ protected: int x; public:virtual…
Q: 5.1 Consider the class class base { public: virtual void iam() cout << “base\n"; }; a. Derive two…
A: The program is written in C++ #include <iostream> using namespace std;class base{ public:…
Q: 3. Write a program to create a base class: "Question3", with protected data member: x (int) and with…
A: CODE:- #include <iostream>using namespace std;class Question3{ protected: int x;…
Q: Write an OOP complete Program(overloading constructor, destructor and pointers )to represent a two…
A: Overloaded constructors have the same name but differ by number and type of arguments. The program…
Q: 3. Write a program to create a base class: "Question3", with protected data member: x (int) and with…
A: CODE:- #include <iostream>using namespace std; class Question3{ protected: int…
Q: sing C++ code, write a program to create a člass base tll ntegers and the interface: • A constructor…
A: SUMMARY: -Hence, we discussed all the points.
Q: Write a program to create a base class: “Question3”, with protected data member: x (int) and with…
A: Note: This code should be rewritten instead of copying to the compiler otherwise it will throw a…
Q: Consider the following class definition class father { protected : int age; public; father (int x)…
A: Given: Consider the following class definition class father { protected : int age; public; father…
Q: Write a program to create a base class: “Question3”, with protected data member: x (int) and with…
A: Pure virtual function in base class has only the declaration of the function without the body of the…
Q: Q 1. a) A class Student has RollNo, name, class Internal_exam has sublmark, sub2marks, class…
A: Include the header files Create a class Student with data member rollno and name Define a getdata()…
Q: Write program for hotel booking system using C++ Program Requirement: a) Create least one (1)…
A: Actually, the code has given below:
Q: Define a class Distance with two private integer members km and m to represent kilometers and meters…
A: A class is a blueprint from which individual objects are created. A class can contain any of the…
Q: eate a program in C++ language to achieve the following tasks: a. Create a ThreeDimensionalShape…
A: #include <iostream> using namespace std;class ThreeDimentionalShape{public: int height =…
Q: solve using oop in c++ Define the base class Base, whose data members are high h, and define the…
A: #include <iostream>using namespace std; class Base{ protected: int h; public:…
Q: Define the class Student which has the private members name, ID, GPA, numberOfCourses, marks[] (one…
A: Below I have provided C++ Programming. Also, I have attached the screenshot of the code and output…
Q: 3. Write a program to create a base class: "Question3", with protected data member: x (int) and with…
A: Pure virtual functions are the functions in which it is declared in the base class and initialized…
Q: 4.a. Consider the class network of the following figure. Person Came code Account Admin salary No of…
A: The program is written in C++ #include <iostream>using namespace std;#include <string>…
Q: 3. Write a program to create a base class: “Question3”, with protected data member: x (int) and with…
A: Given: 3. Write a program to create a base class: “Question3”, with protected data member: x(int)…
Q: For a non-constant member function of class Test, the this pointer has type: elect one: O a. const…
A: Option (b) is Correct Test * const
Q: estion : Define a Class Person with the following member variables a ember functions, d. Member…
A: The code in c++ are given in step 2.
Q: Write a program to create a base class: “Question3”, with protected data member: x (int) and with…
A: Derived class that inherits the properties of the base class properties is called inheritance.…
Q: create a simple “shape” hierarchy in C++: a base class called Shape and derived classes called…
A: Virtual Function is a member function of the base class which is overridden in the derived class.…
Q: This lab practices define class, more particular, identifying the member variables, declaring and…
A: the code is an given below : The code used:#include<iostream>using namespace std;class…
Q: Explain why assigning members to a class with a pointer member may cause problems.
A: Introduction: Member functions can only be called if you provide an object to act as "this" and use…
Q: Consider the class class base public: virtual void iam) cout <« "base\n"; ): Derive two classes from…
A: #include<iostream.h>#include<conio.h>#include<stdio.h> using namespace std; class…
Q: 1. Which is used to create an abstract class? A. Creating at least one member function as a pure…
A: In step 2, I have provided answer with brief explanation---------------
Q: t and function printarea() and a virtual function cal_area(). Create two sub classes Rectangle and…
A: #include<iostream>using namespace std; /* create parent class */ class Shape { protected:…
Q: Q. Write a program to create a base class: "Question3", with protected data member: x (int) and with…
A: Below is the required C++ program: - Approach: - Include the header file and use the namespace std.…
Q: h the same name, excess the function using pointer and virtual functions using c++
A: create a base class and derive classes all having functions with the same name, excess the…
Q: Write a program to create a base class: “Question3”, with protected data member: x (int) and with…
A: Virtual Function: This function is designed to implement runtime polymorphism in programs where the…
Q: 1. Implement a Student class. a. Create a class Student with the following private data members: 1.…
A: Note: We are authorized to answer only one question at a time. Since you have asked more than one…
Q: 3- Write a program to implement a class "student" with the following members. Name of the student.…
A: As per the requirement program is developed. Note: In the question programming language is not…
Q: Q 1. Consider the following class definition class father { protected : int age; public; father (int…
A: Given:
Q: 1.use c++ to Write a program to calculate the volume of various containers. A base class, Cylinder,…
A: C++ program: #include <iostream>using namespace std;const float PI = 3.1415927;class Cylinder…
Step by step
Solved in 4 steps
- This is an object oriented programming question The code should be in C++ language Create a class Student having a private data members S_ID, S_Name and S_CGPA. Now create a public member functions void getID(), void getName() and getCGPA() and finally to display all the data members, create a function void display(). In the main(), create an array of student class, size of the array should be taken from user at run time and call all the functions defined in the class. Sample Output: Student 1 Enter ID: 1 Enter Name: Ali Enter CGPA: 2.5 Student 2 Enter ID: 2 Enter Name: Ahmed Enter CGPA: 2.9 Student 3 Enter ID: 3 Enter Name: Zain Enter CGPA: 3.4 Student 1 informationID: 1 Name: Ali CGPA: 2.5 Student 2 information ID: 2 Name: Ahmed CGPA: 2.9 Student 3 information ID: 3 Name: Zain CGPA: 3.4In c++ Make the print function in the petRecord class virtual. Create a new main that creates a PetRecord pointer, then asks the user if they want a cat, dog or bird, and creates the appropriate pet type at the pointer (use the keyword new and the default constructor). Print its’ information using the print function, including the information specific to that pet type (works due to polymorphism). Finally, delete the object at the pointer. NOTE: Answer only if you know this answer otherwise I wil downvote also don't copy from other platforms ThankyouDevelop class Polynomial . The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent—e.g., the term 2x4has the coefficient 2 and the exponent 4. Develop a complete class containing proper constructor and destructor functions as well as set and get functions. The class should also provide the following overloaded operator capabilities: "Overload the subtraction operator ( - ) to subtract two Polynomial s."
- Using Base class pointer create a derived class dynamic object. Set values of dynamically created object using base class pointer (use arrow operator with pointer of base class). Call Area function of derived class using base class pointer. Delete pointer of base class as it has fulfilled its duty. CODE GIVEN BELOW #include <iostream> using namespace std; class CPolygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; } virtual int area () { return (0); } }; class CRectangle: public CPolygon { public: int area () { return (width * height); } }; class CTriangle: public CPolygon { public: int area () { return (width * height / 2); } }; int main () { CRectangle rect; CTriangle trgl; CPolygon poly; CPolygon * ppoly1 = ▭ CPolygon * ppoly2 = &trgl; CPolygon * ppoly3 = &poly; ppoly1->set_values (4,5); ppoly2->set_values (4,5); ppoly3->set_values (4,5); cout << ppoly1->area() << endl; cout <<…Write a class Employee with data members Name, Id, and Salary. Derive two classes, Faculty with data members Department, and role(permanent or visiting) and derived class Management with data members Department and rank (manager, deputymanager, etc.). Create getters,settersfor all thedata members, create constructors,destructors and show functions for all the classes.Create a write function to write employees on a file . In main function create two objects of each derived class using parameterized constructors, call the show function to show all four objects, write all four objects to a file. Your submission should include the output file.please use c++ to answer the following question Use inheritance and classes to represent a deck of playing cards. Create a Card class that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack)along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: Print every card in the deck Shuffle the cards in the deck. You can implement this by randomly swappingevery card in the deck. Add a new card to the deck. This function should take a Card object as a parameter and add it to the vector. Remove a card from the deck. This removes the first card stored in the vector andreturns it. Sort the cards in the deck ordered by name. Next, create a Hand class that represents cards in a hand. Hand should be derived from Deck. This is because a hand is…
- The base class Pet has protected data members petName, and petAge. The derived class Dog extends the Pet class and includes a private data member for dogBreed. Complete main() to: create a generic pet and print information using PrintInfo(). create a Dog pet, use PrintInfo() to print information, and add a statement to print the dog's breed using the GetBreed() function. Ex. If the input is: Dobby2Kreacher3German Schnauzer the output is: Pet Information: Name: Dobby Age: 2Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer #include <iostream>#include<string>#include "Dog.h" using namespace std; int main() { string petName, dogName, dogBreed; int petAge, dogAge; Pet myPet; Dog myDog; getline(cin, petName); cin >> petAge; cin.ignore(); getline(cin, dogName); cin >> dogAge; cin.ignore(); getline(cin, dogBreed); // TODO: Create generic pet (using petName, petAge) and then call PrintInfo //…please use C++ Programming Language to answer the following question Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: • Print every card in the deck • Shuffle the cards in the deck. You can implement this by randomly swapping every card in the deck. • Add a new card to the deck. This function should take a Card object as a parameter and add it to the vector. • Remove a card from the deck. This removes the first card stored in the vector and returns it. • Sort the cards in the deck ordered by name. Next, create a Hand class that represents cards in a hand. Hand should be derived from…Create parent class Shapes with protected parameters width and height and function printarea() and a virtual function cal_area(). Create two sub classes Rectangle and Sqaure. In main() create 2 pointers of Shapes and assign Rectangle and Square to it. Call printarea function with the pointers. Implement using abstract class. Note: use OOP and C++
- Create a class: Doctor, with private data members: id, name, specialization and salary with public member function: get_data () to take input for all data members, show_data () to display the values of all data members and get specialization () to return specialization. Write a program to write for detail of n doctors by allocating the memory at run time only. Write the program in c++ language. ( Hint: Use the concept of dynamic memory allocation )A class Student has Roll No, Branch, class Internal_exam has sub1marks, sub2 marks, class External_exam has sub1marks and class Result has Total as data members. Write necessary member functions to input and print data. (i) Calculate Internal_exam and External_exam subtotals using their respective member functions.(ii) Class Result has a function to calculate Total=internal+ external subtotals. Write a complete program to implement the hierarchy of the classes using virtual base class.Answer this in C++: Given main(), complete the Calculator class (in files Calculator.h and Calculator.cpp) that emulates basic functions of a calculator: add, subtract, multiple, divide, and clear. The class has one private data member called value for the calculator's current value. Implement the following constructor and public member functions as listed below: Calculator() - default constructor to set the data member to 0.0 void Add(double val) - add the parameter to the data member void Subtract(double val) - subtract the parameter from the data member void Multiply(double val) - multiply the data member by the parameter void Divide(double val) - divide the data member by the parameter void Clear( ) - set the data member to 0.0 double GetValue( ) - return the data member Given two double input values num1 and num2, the program outputs the following values: The initial value of the data member, value The value after adding num1 The value after multiplying by 3 The value after…