Assigned: Week of October 8, 2012
Due: At the end of the
lab session
I. Learner
Objectives:
At the conclusion
of this programming assignment, participants should be able to:
- Design,
implement and test classes in C++
- Declare
and define constructors
- Declare
and define destructors
- Compare
and contrast public and private access specifiers
in C++
- Describe
what is an attribute or data member
of a class
- Describe
what is a method of a class
- Apply
and implement overloaded functions
- Distinguish
between pass-by-value and pass-by-reference
- Discuss
classes versus objects
II.
Prerequisites:
Before starting
this programming assignment, participants should be able to:
- Analyze
a basic set of requirements for a problem
- Compose
a small C++ language program
- Create
test cases for a program
III. Overview & Requirements:
This lab, along with your TA, will help you navigate through designing,
implementing, and testing classes in C++.
Labs are held in a “closed” environment such that you may ask your TA
questions. Please use your TAs knowledge to your advantage. You are required to
move at the pace set forth by your TA. Please help other students in need when
you are finished with a task. You may work in pairs if you wish. However, I
encourage you to compose your own solution to each problem. Have a great time!
Labs are a vital part to your education in CptS 122
so work diligently.
Tasks:
- Write
a class called CreditReport. This class
represents a real-world credit report. It should contain a credit score (ranges
330 – 830), a debt profile (total real estate and credit card debt), account
types (number of real estate, credit cards, and retail cards), length of
history (oldest account age and average account age), and number of hard
inquiries (number of times your credit report has been accessed) as
attributes. Operations that may be applied to your CreditReport
include: printReport and updateReport
(you may refine updateReport for use with individual
class attributes). Be sure to include all necessary getters and setters,
constructors, and destructors. At this point, do not define a copy
constructor or overloaded operators. Use the automatic copy constructor
which is generated for each class. Write an application which instantiates
three credit reports. These include Experian, TransUnion, and Equifax. Your application should
decrease credit scores as the credit limit on cards is approached and increase
scores as the credit is paid off. Also the older the credit accounts, the
higher the credit score. Also, use the other attributes of the CreditReport as you see fit.
- Complete
programming project Complex numbers from your Deitel
and Deitel C How to Program book (Exercise 17.5).
Create a class called Complex
for performing arithmetic with complex numbers. Write a program to test your
class. Complex numbers have the form
realPart + imaginaryPart * i
where i
is
sqrt (-1)
use double variables to represent
the private data of the class. Provide a constructor that enables an object of
this class to be initialized when it is declared. The constructor should
contain default values in case no initializers are
provided. Provide public member functions that perform the following tasks:
a) Adding two Complex numbers: The real parts are added together and the
imaginary parts are add together.
b) Subtracting two Complex numbers: The real part of the right operand
is subtracted from the real part of the left operand, and the imaginary part of
the operand.
c) Printing Complex numbers in the form (a, b), where a is the
real part and b is the imaginary part.
BONUS: Explore how
to overload the + and – operators. This is not a requirement for this problem!
IV. Submitting Labs:
- You are
not required to submit your lab solutions. However, you should keep them in a
folder that you may continue to access throughout the semester. You should not
store your solutions to the local C: drive on the Sloan 353 machines. These
files are erased on a daily basis.
V. Grading Guidelines:
- This
lab is worth 100 points. Your lab grade is assigned based on completeness and
effort. To receive full credit
for the lab you must show up on time and
continue to work on the problems and complete all the
problems
until the TA has dismissed you.