CMPE-011-Module-2-Declaring-Variables (1)
CMPE-011-Module-2-Declaring-Variables (1)
and Programming
Lecture
Module 2
Declaring Variables
Objectives:
At the end of this lesson, students will be able to :
.
2. Multi-line Comments
• Integer (int)
• Floating Point (float, double)
• Character (char)
• Boolean (bool)
1. Integer (int)
Example
Example
Example:
Example:
int main() {
// Declaring variables
int numStudents = 30; // Integer variable
float height = 5.9f; // Float variable
double weight = 70.5; // Double variable
char grade = 'A'; // Character variable
Without endl;
With endl;
Number of Students: 30
Height: 5.9 feet
Weight: 70.5 kg
Grade: A
Has Graduated: No
cout
cout (short for "character output") is an object in C++ used for
outputting data to the standard output stream, usually the
console.
It is part of the iostream library, which must be included at the
beginning of your program.
The basic syntax of using cout is:
<< is the stream insertion operator that directs the output to the cout stream
Common Uses of cout
Example
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Modulus (%) – returns the remainder of a division
operation.
Example
You can use \n to insert new lines instead of using std::endl.
Make a c++ program to compute the
1. Area of rectangle
2. Area of circle pi x r2
3. Perimeter of a rectangle
4. Circumference of a Circle 2*pi*r
5. Conversion of peso to dollar
6. dollar to peso
6. feet to inch
7. cm to meter
8. minute to hour
9. hour to minutes
10. Salary of an employee given the number of hours per week and rate per day of
the employee. Compute for the salary per month.
Thank you. End of lesson.