📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 138question

Data Types, Variables and Expressions · Part 13

Chapter 3: 4 · Computer Science

specific number of digits. Syntax: setprecision (number of digits); Example: #include <iostream> #include <iomanip> using namespace std; int main() float hra = . ; cout << setprecision ( ) << hra; } In the above code, the given value . will be displayed in digits including fractions.

So, the output will be . setprecision ( ) prints the values from left to right. For the above code, first, it will take digits and then prints one digit from fractional portion. setprecision can also be used to set the number of decimal places to be displayed.

In order to do this task, you will have to set an ios flag within setf() manipulator. This may be used in two forms: (i) fixed and (ii) scientific These two forms are used when the keywords fixed or scientific are appropriately used before the setprecision manipulator. Example: #include <iostream> #include <iomanip> using namespace std; int main() cout.setf(ios::fixed); cout << setprecision( )<< . ; } Chapter Page - - In the above program, ios flag is set to fixed type; it prints the floating point number in fixed notation.

So, the output will be, . cout.setf(ios::scientific); cout << setprecision( ) << . ; In the above statements, ios flag is set to scientific type; it will print the floating point number in scientific notation. So, the output will be, .00e- .

Expression An expression is a combination of operators, constants and variables arranged as per the rules of C++. It may also include function calls which return values. (Functions will be learnt in upcoming chapters). An expression may consist of one or more operands, and zero or more operators to produce a value.

In C++, there are seven types of expressions, and they are: (i) Constant Expression (ii) Integer Expression (iii) Floating Expression (iv) Relational Expression (v) Logical Expression (vi) Bitwise Expression (vii) Pointer Expression SN Expression Description Example Constant Expression Constant expression consist only constant values int num= ; I n t e g e r E x p r e s s i o n The combination of integer and character values and/or variables

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →