Unit 02 - Unit02 It'saBigWorld. UnitObjectives

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

View Full Document Right Arrow Icon
Unit 02 It's a Big World. Unit Objectives   Learn the fundamental data types used to store data. Learn how to collect data from user. Perform some more complicated math operations on our data. Understand how to ask the most important question in C++? Hint: it begins with if. .. Understand Enumeration: A simple way to make your own data types.   Introduction Congratulations! You have finished your first Readiness Test with no errors. You should be proud that you  have actually written and compiled a simple stand alone application. I know it did not do a whole lot. ....yet.  And now it is time to move past simple greetings and a glorified calculator. So what kind of functionality do we need? We will need our program to store data. We will need to ask  users for input. And we will need to it check this input to make sure they didn't do anything silly that might  confuse our program. Once we have these three basic elements in place, we are going to quickly review  enumeration which will hint at the power of C++. Finally we will take a quick look under the hood so you  can understand just a little about how the compiler gets the computer to follow your instructions. Task 1 - Storing your data. Back in high school when you studied algebra, you were always looking for the value of the mysterious  x As you learned then,  x  was a variable and took on different values in different problems. Well, programs  have variables too. These variables are placeholders for values that can change during the course of a  program. In C++, there are 5 fundamental data types  we can use when creating variables. 1. booleans (called bool: true or false) 2. characters (called char) 3. integers (called int) 4. floating point numbers (called float)
Background image of page 1

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

View Full DocumentRight Arrow Icon
5. double precision floating point numbers (called double) Each time you want to create a new instance of a data type, you must give it a name so the compiler can  tell it apart from all the other data types. These are called  variables  which can be  declared  in C++ rather  simply. bool myBool = false; char myChar = 'a'; char anotherChar = 'T'; int a = 3; float radius = 5.67; double lightspeed = 299792458; When you first declare a variable, you don't have to give it a value. But it is strongly recommended that always you do . When you don't assign a value, the compiler doesn't either, not even a common sense value like 0. So if don't assign values, the assumed values are essentially random. I have seen this confuse a lot of beginning programmers. Depending on the data type you choose, the C++ compiler will do different things, it will treat your data in 
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 / 13

Unit 02 - Unit02 It'saBigWorld. 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