Basic Syntax, Data Types, and Variables
CITE 002 - Computer Programming 1
By: Eduardo S. Rodrigo
Intended Learning Outcomes (ILO)
INTENDED LEARNING OUTCOMES
At the end of the lesson, the students are expected to :
1) describe the data type, variable, and identifier;
2) define the variable naming convention;
3) use the cin and cout functions;
4) use the different operators of C++;
4) create a transactional C++ program.
C++ Programming Data Types
101 short
200,980 integer
1,280,780,345 long
125.70 float
1,280,780,345.50 double
DATA TYPE
string
101-MIN
char
W
String
pcs
short
50
float
12.50
C++ Programming Data Types
DATA TYPE
String
101
String/Date
10/24/2020
String
ABC Marketing
BR-156-DC
Rebisco
Rebisco Sandwich
Bread
150
int
56.00 float/double
C++ Programming Variables and Identifiers
Rules for Naming a Variable (identifier) :
1)A variable name can only have letters (both uppercase
and lowercase letters), digits, and underscore.
2)The first letter of a variable should be either a letter or an
underscore.
3) It is not a C Language keyword.
example : gets, puts, printf, main cout cin…
4) Do not use special characters such as : $, %, - , @ within
identifiers.
5) It must be a logical identifier.
Tell whether the following Identifiers are valid or invalid.
age_45
Qty_of_Stock
Philippines
_dateOfBirth
Qty-no
break
tokneneng
case
123CustomerNm
CustomerNm123
CustomerNm_123
Computation of Basic Salary
Name of Employee :
Department :
Rate Per Day :
Days Worked :
Gross Salary :
Less Deductions :
Cash Advance :
Tax :
SSS :
Absences :
Net Salary :
#include<iostream>
using namespace std;
main()
{
string employeeName, dept;
float ratePerDay, daysWorked;
float gross=0, deduction=0, netsalary=0;
float cAdvance,tax,sss,absent;
cout<<"Name of Employee : ";
getline(cin,employeeName);
cout<<"Department : ";
cin>>dept;
cout<<"Rate Per Day : ";
cin>>ratePerDay;
cout<<"Days Worked : ";
cin>>daysWorked;
gross= ratePerDay * daysWorked; (continue to the next slide)
cout<<"---LESS DEDUCTION---";
cout<<"\n Cash Advance : ";
cin>>cAdvance;
cout<<"Tax : ";
cin>>tax;
cout<<" SSS : ";
cin>>sss;
cout<<"Absences : ";
cin>>absent;
netsalary = gross-(cAdvance + tax + sss + absent);
cout<<"______________________";
cout<<"\n\n EMPLOYEE PAYSLIP";
cout<<"\n______________________";
cout<<"\n\n Name of Employee : " <<employeeName;
cout<<"\n Employee Department : "<<dept;
cout<<"\n Gross Salary : " <<gross;
cout<<"\n\n Net Salary : " <<netsalary;
}