Answered step by step
Verified Expert Solution
Question
1 Approved Answer
COMP 53: Objects and Classes Lab, part 1 Instructions: In this lab, we are going to review objects and classes. - Get into groups of
COMP 53: Objects and Classes Lab, part 1 Instructions: In this lab, we are going to review objects and classes. - Get into groups of at most two people to accomplish this lab. - At the top of your source code list the group members as a comment. - Each member of the group must individually submit the lab in Canvas. - This lab includes 33 points in aggregate. The details are given in the following. 1 Class State In this lab, you are going to define class State consisting of the following details. 1. Each State has the following data components: - The name of the state: name - The population of the state: population Each of the aforementioned data components must be hidden from the class user ( 2 points). 2. For each of the aforementioned data components, define the setter. The setter of a data component assigns the input to that data component. Let the setter function for name and population be named setname and setPopulation, respectively. Both setters must be visible to the class users ( 6 points). 3. All setters must be defined in inlined form ( 2 points). 4. For each of the aforementioned data components, define the getter. The getter of a data component returns that data component. Let the getter function for name and population be named getName and getPopulation, respectively. Both getters must be visible to the class users. In addition, each getter must be constant (6 points). 5. All getters must be defined in inlined form ( 2 points). 6. The definition of class State includes the default constructor that sets - state name to N/A, and - state population to 0. In addition, avoid inlined form for its definition (3 points). 7. The class State includes a private helper function size() that returns small, medium, or large according to the state's population. The details are as follows: - If the population is less than 1 million, then it returns small. - If the population is larger than 1 million but less than 5 million, then it returns medium. - If the population is larger than 5 million, then it returns large. This function must be a constant function. In addition, avoid inlined form for its definition (4 points). 8. The class State includes a public function void printsize() that invokes getName () along with size () to print the state name and its size in the standard output. printsize () must be a constant function. In addition, avoid inlined form for its definition ( 3 points). 2 Main function Define main function that does the following step by step. 1. Create an object of class State, called state1 (1 points). 2. Invoke printsize() function of state1 object (1 points). 3. Set the name and population for statel to be California and 40000000 , respectively (2 points). 4. Invoke printSize () function of statel object (1 points). The output of the program may look like the following: N/A: small California: large
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started