Preview

C++ Lab Session

Good Essays
Open Document
Open Document
868 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
C++ Lab Session
sion Computer programming using C++
Given the following classes, write the implementation codes and the driver program to demonstrate inheritance using C++. You may add other appropriate member functions and / or data members.

class DemoBasePerson
{
private: double salary; protected: int age; public: char initial; void setPerson(double, int, char); //sets values for salary, age and initial void showPerson( ); //displays values stored in salary, age and initial }; class Extrovert: public DemoBasePerson
{
private: string favSports; protected: double expenditure; public: int noOfEventsPerYear; void setExtro (string, double, int); //sets values for favSports, expenditure, noOfEventsPerYear //& data in the base class void showExtrovert( ); //displays values for favSports, expenditure, noOfEventsPerYear //& data in the base class

}; class Introvert: private DemoBasePerson
{
private: string passWord; protected: string loginId; public: string status;//active or passive void setIntro (string, string, string); //sets values for password, loginId, status //& data in the base class void showIntrovert( ); //displays values for passWord, loginId, status //& data in the base class
};
class SomeWhatShy: protected DemoBasePerson
{
private: string homeName; protected: string maritalStatus; public: string birthDate; void setSomeWhat(string, string, string); //sets values for homeName, maritalStatus, birthDate //& data in the base class void showSomeWhat( ); //displays values for homeName, maritalStatus, birthDate //& data in the base class
};
SOLUTION

#include<iostream>
#include<string>
using namespace std;

class DemoBasePerson
{
private: double salary; protected: int age; public: char initial;

void setPerson(){ double sal; int ag; char initi;

You May Also Find These Documents Helpful

  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    class Link { public int iData; // data item public double dData; // data item public Link next; // next link in list // ------------------------------------------------------------public Link(int id, double dd) // constructor { iData = id; // initialize data dData = dd; // ('next' is automatically } // set to null) // ------------------------------------------------------------public void displayLink() // display ourself { System.out.print("{" + iData + ", " + dData + "} "); } } // end class Link //////////////////////////////////////////////////////////////// class LinkList { private Link first; // ref to first link on list // ------------------------------------------------------------public LinkList() // constructor { first = null; // no links on list yet } // ------------------------------------------------------------public boolean isEmpty() // true if list is empty { return…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    Garbage Collector in C#: Runtime has a Garbage Collector Which cleans the objects that are not in use.…

    • 485 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Synthesis Lab

    • 435 Words
    • 2 Pages

    At the beginning of the lab, a micro test tube with and without glass wool was weighed on an analytical balance. A watch glass, crucible, and lid were also weighed. The masses of all the materials needed for the lab were recorded in the data tables of the laboratory notebook. An unknown vial was obtained from the teacher and set to zero on the balance. About 0.6 grams of the unknown was measured into the micro test tube. The analytical balance was set to zero again and then the test tube with the unknown was measured and recorded.…

    • 435 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Structured Query Language (SQL) is a standard database computer language used for querying, modifying and managing data in Relational Database Management Systems (RDBMS). SQL was developed in the 1970's by IBM to initially manipulate and retrieve data in IBM System R. The SQL language was standardized in 1986 by the American National Standards Institute (ANSI); however, later releases were released as International Organization for Standardization (ISO) standards.…

    • 612 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    c. Modify the program of Part b so that at the option of the user, it displays…

    • 300 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Cs Programming Chapter 1

    • 2450 Words
    • 10 Pages

    ____ data items may involve organizing or sorting them, checking them for accuracy, or performing calculations with them.…

    • 2450 Words
    • 10 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Lab 7 Student

    • 1242 Words
    • 7 Pages

    This lab accompanies Chapter 5 (pp. 163-183 and pp. 196-201) of Starting Out with Programming Logic & Design.…

    • 1242 Words
    • 7 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Virtual Lab

    • 463 Words
    • 3 Pages

    Make a hypothesis about how you think the two species of Paramecium will grow alone and how they will grow when they are grown together.…

    • 463 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Info1105

    • 951 Words
    • 4 Pages

    You are NOT allowed to use any 3rd‐party libraries for this assignment. All code must be your own work. NOTE: You should write your own set of JUnit tests in the test files to ensure your 4 classes are working. Part of the assignment will be automatically marked, and you will only be allowed THREE (3) attempts in total. Each required file is covered in more detail below. A skeleton project has also been provided through eLearning.…

    • 951 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    concepts of classes, objects, constructors, methods, access control, this keyword, overloading methods and constructors, parameter…

    • 414 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Intro the Programming

    • 386 Words
    • 5 Pages

    In general terms, a program that is broken into smaller units of code, such as methods, is known as a(n) _______.…

    • 386 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    Each new class obtained through inheritance is known as derived class, and classes from which it derives are called base classes. In addition, each derived class can be used as a base class for a new derived class. And each derived class can be one or more base classes. In the latter case are referred to bypass manifold.…

    • 290 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Programming Homework

    • 366 Words
    • 2 Pages

    Write a program that would calculate and display the results for the multiplication table for values ranging from 1 to 100.…

    • 366 Words
    • 2 Pages
    Good Essays
  • Good Essays

    On Friday July 15, my group of medical student visited the simulation laboratory. After climbing a couple sets of stairs we were broken off into three different groups for three different sets of activities. The first for me a combination of a couple of simulations. The first one was a simulation designed to help surgeons further develop their skills. We used small clamps to pick up and move rings to different poles. This seems quite simple but we had to do it looking at a monitor that projected what we would see and that new perspective made it much more difficult than anticipated. Next and finally for the first rotation was the colonoscopy. During the colonoscopy simulation, we were given a summary of the problem the patient was experiencing. Next, we were given a joystick that controlled the direction of the cord and while one person was directing, another was feeding the tube in at a slow pace. This…

    • 591 Words
    • 3 Pages
    Good Essays
  • Good Essays

    As a student at Prince Georges Community College I like to take full advantage of all the resources available to me since at the end of the day I am paying for them. This sometimes includes staying a few hours on campus and doing my work instead of waiting until I get home to do it. One major problem that I encounter on a daily basis on the PGCC campus is the campus computer labs. I can never walk into computer lab without leaving out due to it being over crowded, little or no staff being around to help, or computers not working. As a PGCC student I believe this is a huge issue that really needs to be taken more seriously.…

    • 1001 Words
    • 5 Pages
    Good Essays