100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

COS132 Chapter 3 summary

Rating
-
Sold
-
Pages
9
Uploaded on
20-04-2022
Written in
2021/2022

Summary study book Starting Out with C++ of Tony Gaddis - ISBN: 9780132926867 (Detailed summary)










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Summarized whole book?
Yes
Uploaded on
April 20, 2022
Number of pages
9
Written in
2021/2022
Type
Summary

Content preview

COS132 Chapter 3



COS 132
CHAPTER 3 – EXPRESSIONS AND INTERACTIVITY
UNIT 3.1- THE CIN OBJECT


The cin object can be used to read data typed at the keyboard.

cout << “What is the length of the rectange? ”; // This is know as a prompt

cin >> length;

The “>>” symbol is the stream extraction operator, it gets the characters from the stream object onits left and stores
them in the variable whose name appears on the right. The << and >> operators point in the direction that the data is
flowing.

The cin object causes a program to wait until data is typed at the keyboard and the enter key is pressed. Cin
automatically converts the inputted data to the data type of the variable.

NB – you must include <iostream> header file in any program that uses cin.


ENTERING MULTIPLE VALUES
cin >> length >> width;

The enter key is pressed after the last number is entered. Cin will also read multiple values of different data types.




When the user types a value, those first values are stored in an area memory known as the keyboard buffer.

UNIT 3.2 – MATHEMATICAL EXPRESSIONS

C++ allows you to construct complex mathematical expressions using multiple operators and grouping symbols.

Result = 4;

Result = ;

Result = a + b + c;

1|P a g e

, COS132 Chapter 3



OPERATOR PRECEDENCE
Highest - (unary negation)

* / %

Lowest + -


ASSOCIATIVITY
An operators associativity is either to the left or the right, if two operators sharing an operand have the same
precedence, they work according to their associativity.

- (unary negation) Right to left

* / % Left to right

+ - Left to right


GROUPING WITH PARENTHESES
This forces some operations to be performed before others.


NO EXPONENTS PLEASE!
Raising a number to a power requires the use of a library function, called pow.

area = pow(4.0, 2.0);

This statement contains a call to the pow function, the numbers inside the brackets are called arguments (= data being
sent to the function). The pow function raises the first argument to the power of the second argument. The result is
returned from the function and used in the statement where the function call appears.

The program must include <cmath> header file, and the arguments that you pass to the pow function should be doubles.
The variable used to store pow’s return value should also be double.

UNIT 3.3 – WHEN YOU MIX APPLES AND ORANGES: TYPE CONVERSION

When an operator’s operands are of different data types, C++ will automatically convert them to the same data type(this
is known as type coercion). When a value is converted to a higher data type it is promoted, and when it is converted to a
lower data type, it is demoted.




2|P a g e

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
jennamortonx IIE Varsity College
View profile
Follow You need to be logged in order to follow users or courses
Sold
18
Member since
3 year
Number of followers
1
Documents
49
Last sold
5 months ago

4,0

1 reviews

5
0
4
1
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions