EL – 125 Programming Fundamentals

Experiment # 01

Working with Constants, Variables and Arithmetic Operators
Performed on 27 Feb, 2017

Student Name:
Roll Number:

Maximum Marks Performance = 05 Viva = 05 Total = 10
Marks Obtained

Remarks (if any)

Experiment evaluated by

Instructor Name:

Signature and Date:

Copyright © Department of Electrical Engineering – Usman Institute of Technology

Variables and Keywords. which is written as >> which are two greater than signs Copyright © Department of Electrical Engineering – Usman Institute of Technology . which usually is the display screen. which are sequences of bytes. The standard output stream (cout): The predefined object cout is an instance of ostream class. VAR2. Variables: An entity that may vary during program execution. Keyword: A predefined word that cannot be used as a variable name. Value Assignment to the Variable: Depending on the data type. It is also called “Reserved Words”. The cout object is said to be "connected to" the standard output device. The cin is used in conjunction with the stream extraction operator. a programmer can assign proper value to the variable. Character Set of C++: It is a Combination of Alphabets. a disk drive. or a network connection. You can also declare more than one variables of same type by using comma-separated list. Basic Input and Output: C++ I/O occurs in streams. The standard input stream (cin): The predefined object cin is an instance of istream class. which is written as << which are two less than signs. If bytes flows from a device like a keyboard. etc. this is called input operation and if bytes flows from main memory to a device like a display screen. The cout is used in conjunction with the stream insertion operator. Digits. VAR 3…. For Example: a=10. For example TYPE VAR1. this is called output operation. The general form of an assignment statement is variable_name = value.Theory Constants: Constant is an entity that does not change. The cin object is said to be attached to the standard input device. and Special symbols to form Constants. which usually is the keyboard. to main memory. or a network connection etc. a printer. Here “Type” is C++ data type and “VAR” is the variable name. a disk drive. For Example: cout <<“Welcome to Programming Fundamentals Lab”. Variable Declaration: Variable is generally declared as: TYPE VAR.

10 * 4 But the following produces result of ‘120’: (40 . cin>>val. -. *=. 10 + (5*2) = 20 a * b % c. a + b * c. 40 . a programmer can alter the order of evaluation using parentheses. (10 * 5) % 2 = 0 Copyright © Department of Electrical Engineering – Usman Institute of Technology . /. C++ describes the following arithmetic operators: Operator Operation + Addition . =) are right associative. -=.10) * 4 Operators Associatively: Associatively may be left associative (left to right) or right associative (right to left). * operators are used with any of the data type but % operator can only be used with integer type only. the result of the following expression is ‘0’. =.For Example: int val. %=. For Example: int a=10. The *. Subtraction * Multiplication / Division % Modulus or Remainder The +. C++ expression follows the rules of algebra. For example. / and % operator are higher precedence than the + and – operators. c=2. However. cout<< “Enter an integer value:”. All arithmetic operators are left associative. Arithmetic operator and Expression: An expression is a combination of operators and operands to make programming easier and efficient. b=5. assignment operators (+=. Operator Precedence: For an expression it is necessary to know about the order of precedence of arithmetic operators.

5 ? = (? − 32) ∗ 9 Home Task: 1. Write a program in C++ (already discussed in the class) to display the sizes of various data types and complete the following table: Data Type Memory Size in Bytes Integer Long Integer Character Short Long Double Floating Point 2. b. } Do it yourself Simple Task: 1.0/3.Observations Program #include <iostream> using namespace std. float f. return 0. Write a program to convert this temperature into Centigrade. Multiplication and division of two numbers) Copyright © Department of Electrical Engineering – Usman Institute of Technology . f = 70. cout << f << endl . Take length & breadth of a square and radius of a circle as input through the keyboard. Subtraction. (Hint: Perform Addition. cin >> a. int main () { // Variable declaration int a. int c. // initialization b = 20. Temperature of a city in Fahrenheit degrees in input through the Keyboard. cout << c << endl . Write a program for which can perform simple arithmetical operations take input from user.0. Write a program to calculate the area of the square and the area and circumference of the circle 3. c = a + b. cout<<”Enter value of a:\n”.