{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Unit 15 - Unit15 CreatingClassesinC UnitObjectives /ordata...

This preview shows pages 1–3. Sign up to view the full content.

Unit 15 Creating Classes in C++ Unit Objectives   Learn how to create your own classes. Learn how to create class constructors. Learn how to write methods for your class. Learn the difference between public and private methods and/or data.   Introduction In the last section we learned about objects and classes. We learned how to use example classes such  as ComplexNumber and Account in our own programs. But we could only look at the code, because these  classes didn't exist ...... yet ! In this unit, you are going to create these classes and use them in an  application. Once you know how to create classes, I can introduce a few new C++ keywords to help us  tailor our new classes to meet our exact needs. Task 1 - Learning by doing...The ComplexNumber Class. What is a  Complex Number ? Complex numbers were first considered when mathematicians  discovered it was possible to solve many polynomial equations even though terms with square roots of  negative numbers appeared in the intermediary steps. Later in your mechanical engineering education,  you will see them quite a bit since they are common in  Control Theory  and  Mechatronics . Let's  methodically go through all the steps of creating and testing a ComplexNumber class we can use to store  and manipulate complex numbers. In the next unit test, you will be asked to add code to the complex number class we will create together below. You will find the test much easier if you create the class below as you

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
go along. Since time is limited during a test, you may have trouble finishing if you have to create the class from scratch. Step 1 - Define Class Properties and Functionality What properties describe the state of a Complex Number? What kinds of operations and/or functionality  would we like it to have? For the sake of keeping this class simple, we won't add every conceivable  operation and function listed here. But pay close attention since we may add functionality in one of the  exercises below or as part of a unit test. The properties for a ComplexNumber are straight forward.   Real scalar value (stored as a double) Imaginary scalar value (stored as a double)   What functionality would we like to have?   Add two complex numbers and store the result. Multiply two complex numbers and store the result. Print complex numbers to the console.   I can think of many more than I have listed, but that is enough for now.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern