Last Time…. Operators Arithmetic Operators Assignment Operators Increment/Decrement Operators Relational Operators Logical Operators Expression Statements Introduction to Library Functions. Precedence of Operators. Evaluation the following Expressions: a) 4 + 7 * 6 / 3 – 5
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Evaluation the following Expressions:
a) 4 + 7 * 6 / 3 – 5
b) ++ 23 / - 3 + 3 --
int count = 100;
float avgWeight = 70F;
double totalWeight = count * avgWeight;
cout<<“The total weight in this room = ”<<totalWeight;
Automatic Type Conversion , Compiler handles the type conversion
float a = 4.0;
result = a * 3.56;
<<Compiler Signals a WARNING!>>
How do you cast to another type?
Rule 1: When an operator works with two values of different values of different data types, the lower-ranking value is prompted to the type of the higher-ranking value.
Rule 2: When the final value of and expression is assigned to a variable, it will be converted to the data type of that variable.
[A type cast expression lets you manually promote or demote a value in the same way that automatic conversion takes place.]
A variable or Literal value
Data Type you wish to convert it to
How would you prevent the INTEGER DIVISION?
int books, months;
cout<<“How many books do you plan to read?”
cout<<“How many month will it take you to read them?”
booksPerMonth = books/months;
cout<<“That is”<<booksPerMonth<<“books per month.\n”;
Write a program that implements the following algorithm.
Read the total hours the employee has worked, TotalHours
Read the hourly rate of pay for the employee, HourlyRate
GrossSalary= TotalHours* HourlyRate
Tax = GrossSalary * 0.1
NetSalary = GrossSalary - Tax
[Write a program that will convert U.S. dollar amounts to Japanese yen and to euros. The conversion factors to use are 1dollar = 108.5 yen and 1 dollar = 0.8218 euros]
Addis Ababa Institute of Technology
The mathematical functions allow us to do mathematical operations.
These operations include:
These functions are defined in the header file math.h (or cmath in standard C++).
sqrt is the name of the function that performs the square root operation. This function takes one argument of type double and returns a result of type double.
The function that computes the power of two numbers is :
More examples of mathematical functions are:
What is the output of this program?