Unit 15 - Unit15 CreatingClassesinC+ UnitObjectives

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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. Step 2 - Hello World!
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/02/2011 for the course ME 205 taught by Professor Koen during the Spring '07 term at University of Texas at Austin.

Page1 / 20

Unit 15 - Unit15 CreatingClassesinC+ UnitObjectives

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online