×

### Let's log you in.

or

Don't have a StudySoup account? Create one here!

×

or

## CS 142 Data Types Lecture Notes

by: Ethan Sheppard

134

0

3

# CS 142 Data Types Lecture Notes C S 142

Ethan Sheppard
BYU

Get a free preview of these Notes, just enter your email below.

×
Unlock Preview

These notes cover data types, something necessary for Lab 2 and very helpful for Lab 3 as well.
COURSE
Intro to Computer Programing
PROF.
Samantha Sanders
TYPE
Class Notes
PAGES
3
WORDS
CONCEPTS
data, programming
KARMA
25 ?

## Popular in Computer Science and Engineering

This 3 page Class Notes was uploaded by Ethan Sheppard on Saturday September 10, 2016. The Class Notes belongs to C S 142 at Brigham Young University taught by Samantha Sanders in Fall 2016. Since its upload, it has received 134 views. For similar materials see Intro to Computer Programing in Computer Science and Engineering at Brigham Young University.

×

## Reviews for CS 142 Data Types Lecture Notes

×

×

### What is Karma?

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/10/16
Data Types Wednesday, September 7, 2016 2:59 PM Variable- stores one piece of information. It has a name and a value. Int cans_per_pack = 6; Int- indicates that the variable will hold the value 6. Cans_per_pack- the name of the variable. 6- the value assigned to the variable. You can also define a variable using existing variables. Int total = bottles + cans; Integers- whole numbers without a fractional part; 10, 0, -4. Overflow-if you try and store a value above the range, the number will moveto the other end and becomea negative. Floating-point (double)- numbers with fractional parts; 0.355, -10.98, 0.0 15 significant digits. Variable Naming Rules 1. Variable names must start with a letter or underscore character, remaining characters must be letters, or underscores. 2. You cannot use special symbols or spaces. Use underscores to denote spaces. 3. Variable names are case-sensitive. 4. Reserved words are off limits, such as double or return. The assignment statement-used for placing a new value into a variable. Cans_per_pack = 8; Total = total + cans * CAN_VOULME; The = in an assignment does not mean that both sides equal each other. It is an instruction to do something. It copies the value of the expression on the right into the variable on the left. Sometimesthe programmerknows certain values that won't change. Those are called constants, in code the command is "const". Constants are usually all CAPS. Const int CANS = 8 Magic Numbers- a number used in the program that isn't defined as a variable or a constant. Comments-explanations throughout the program for fellow programmers.The compiler ignores all comments. //Number of cans in a pack. Const int CANS = 8 // means a single line comment. /* /* This is a multiple lined commentthat will include everything in between these slashes and asterisks. */ Arithmetic Operators Order of operations is used in programming. A + B / 2 The B / 2 will happen first. Counter++ will add one to the variable's value. The % operator computes the remainder of an integer division as the / will drop off decimals. Called the Modulus Operator. 24 % 2 = 0 8 % 15 = 8 17 % 5 = 2 Converting doubles to integers Double price = 2.55 Int dollars = price Add 0.5 to price before converting to round to the nearest integer. To use square roots or powers: #include <cmath> at the top of code. Pow(base,exponent) Beware of unintended integer division, as it will give you incorrect answers. Cast- a conversionfrom one type of variable to another. Generally not a safe thing to do, except in specific circumstances. Change = 999.89;// change owed Int cents = static_cast<int>(100* change + 0.5); <type of variable you want to convertto> (the value you want to convert) This comes out to 999989pennies Formatting Output Cout << fixed << setprecision(2)//Specifies that whateverfollows will only print out two decimal places. Cout << ";" << setw(6)//Specifies the total length of characters that will follow. String- a variable that contains text instead of numbers. To use, you must include the header: <string>. String name = "James"; To add a last name, you must do something like the following: Name = name + " Duncan"; Rememberspaces count as characters. Rememberspaces count as characters. Substring- extracting part of a string. You can do this by coordinates(signifies character to start from left, number of characters sub string will contain. String name2 = name.substr(1, 3); //Prints out "ame" as 0 is the first position so 1 starts at "a" then grabs a total of three characters.

×

×

### BOOM! Enjoy Your Free Notes!

×

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

Jim McGreen Ohio University

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Jennifer McGill UCSF Med School

#### "Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over \$500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

Jim McGreen Ohio University

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Parker Thompson 500 Startups

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!
×

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com