Lab 9: Classes

In this lab, we will be writing classes and see how they work with data members and member functions.

Refer to the main to know what parameters the functions take and what they return.

Stage 1: Get, Set (1 Point)

Write a class Dorm with two data members a

 dormName (String) which represents the either "east", "west", "commons",

 roomNumber (Integer) which represents the number of the dorm room

   

  a) Write the set function for each data member:

  the main() accepts the user input for the respective field and passes it to the function.

  The set functions should take the user input and assign that value to the respective data member of the object.

 

  b) Write the get function for each data member:

  The function returns the values of the respective fields and which are displayed in main.

 

  Running the program should like: (input indicated in bold)

  1. Enter dorm name (either east, west, or commons) and room number (e.g. east 51): east 51

     The Dorm is: east 51

 

Stage 2: Display Function  (1 Point)

 

 Write a display function to display the values on the screen.

     with the prompt: "The Dorm is: "

     The function should call the get functions to get the values.

       

 

  Running the program should look like:

      1.Enter dorm name (either east, west, or commons) and room number (e.g. east 51): east 51

         The Dorm is: east 51

         Dorm name and room number are: east 51

 Stage 3: Constructors (Extra Credit)

  a) Write a default constructor for the class to accept commons for dorm name, 11 for room number.

  b) Write a fully qualified constructor for the class, which accepts input from user (in main()).

 

 

  Running the program should look like:

      1. Enter dorm name (either east, west, or commons) and room number (e.g. east 51): east 51

         The Dorm is: east 51

         Dorm name and room number are: east 51

      2. Using default constructor gives:          Dorm name and room number are: commons 11

         Using parameterized constructor gives:    Dorm name and room number are: west 71