CSC 213 Problems Assignment 2, Fall 2012
Notre Dame University–Louaize · Program Design and Data Abstraction II · 2 pages
More CSC 213 files
- Problems Assignment 1 · Fall 2012ProblemsView
- Problems Sec 12.1 · Fall 2007ProblemsView
- Problems Sec 14 · Fall 2007ProblemsView
- Problems Sec 12.2 · Fall 2007ProblemsView
- Problems Sec 10 · Fall 2007ProblemsView
- Problems Sec 7.1 · Fall 2007ProblemsView
- Problems Sec 7 · Fall 2007ProblemsView
- Problems Sec 6 · Fall 2007ProblemsView
Show the text of this problems
Notre Dame University
CSC 213
Faculty Natural & Applied Sciences
Assignment #2
1) To help build software for a nutrionist’s clinic, you are asked to create a class Patient with the
following data members:
Name
a string of variable size (dynamically created). Default Empty String
Gender
a constant value of 1 character. Valid Values:”F” – “M”. Default: “F”
Weight
The weight of the patient in Kg. Valid Values (3.5- 150). Default: 50.0.
Height
The height of the patient in meters. Valid Values (0.50-2.20). Default: 1.65.
Obesity_BMI The value of BMI (Body Mass Index) over which the patient is considered to be
obese. It should be of type float and is shared among all objects of this class .(For our patients
is should be set to 30.0)
And the following member functions:
A constructor with default arguments (integrity checks required).
A calculateBMI function that calculates the Body Mass Index of the patient.
BMI = weight in kilograms / height in meters²
A printPatientInfo function to print on the screen all the information of a patient and prints “The
patient is obese” if his BMI is greater than or equal to Obesity_BMI data member. This function
should have a cascading capability.
An external function decrementWeight that decrements the weight by a certain value, calculates
the new BMI and print on the screen if the patient is still obese or not. This external function
should be able to access by name all members of your class.
Write a program to test your class:
-
Create 2 patients objects.
-
Fill the objects created with different patients information.
-
Test all written functions on these patients.
2)
2.1 - Design a class point that has x and y coordinates as data members:
Include the following member functions:
Constructor with arguments
Constructor without arguments (Default constructor)
Scale function: void scale(double a)
This function is supposed to scale the coordinates of the point by a, i.e., multiply each by the
real number a.
Print function: void print()
This function is supposed to print a point on the screen in the format: [x,y]
Distance function: double distance(Point q).
This function should calculate and return the distance between 2 points.
The following formula gives the distance between two points (x1, y1) and (x2, y2) in the
Cartesian plane:
sqrt((x2 − x1)2 + (y2 − y1)2)
It will be used as follows:
void main(){
Point p(5,6);
Point q(7,8);
cout << p.distance(q) <<endl; //calculates and print the
// distance between p and q;
}
2.2 Using the class point, design the class circle.
In addition to the data member center which is of type point, include the data member radius (which is a
real number).
Include the following functions:
Constructor with arguments
Constructor without arguments (Default constructor)
print member function which displays the radius and the x and y coordinates of center
area member function which returns the area of the circle
translate member function which takes as input argument a point p and translates the center of
the circle by p
contains member function which takes as input argument a point p and checks whether or not p is
inside the circle (hint: the distance between the center and the point should be less than or equal
to the radius)
Write a program to test your classes and functions.
Submission
The following should be returned to the instructor in a folder:
1. A first page with your name, the assignment number.
2. Problem Description.
3. A listing of your programs (class and client program) well documented.
4. A screen capture of the output of your program.
Due date: Friday, November 23, 2012