Skip to main content

Posts

Showing posts from March, 2023

Data Representation

 Digital Number System In digital representation, various number systems are used. The most common ones are : Binary : base 2 (0, 1) Octal : base 8 (0, 1, 2, 3, 4, 5, 6, 7) Decimal : base 10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Hexadecimal : base 16 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) Number Conversions : From Decimal to any system (base) (Decimal) 10 = (Any) base

WAP to check whether the given character is uppercase, lowercase, digit or special character

 

Basic OOP concepts

Data Abstraction :  representing essential features without including background details. Example : driving a car (wiring, motor working is hidden from us), switch board (hidden wiring)

Cheat sheet

 A ( 65 ) - Z ( 90 ) a ( 97 ) - z ( 122 ) 0 ( 48 ) - 9 ( 57 ) enter - 13 space - 32 @ - 64 Who calls main()?   OS.  Execution starts at main. <<  : output / put to / stream insertion operator >>  : input / get from / stream extraction operator calculation R to L printing L to R

Selection statement

  If statement  If tests a particular condition, if the condition evaluates to true then set of statements under the body of 'if' statement will be executed otherwise it will be ignored by the compiler. Syntax : if(<condition>) {      statements; } <> : programmer defined If else statement If we use 'else' statement with 'if' statement then if the condition of 'if' statement evaluates to false, in that case body of else statement will be executed, otherwise it will be ignored. Syntax :  if(<condition>) {      statements; } else {     statements; } If-else-if ladder If we use 'else if' statement with 'if' statement then if any condition evaluates to true, in that case its associated statement will be executed and all other 'else if' and 'else' statement will be ignored by the compiler. Syntax :  if(<condition>) {      statements; } else if(<condition>) {    statements; } els...

Operators

  The operations are represented by operators and the object of the operation are referred to as operands. 5 types of operators: 1. Arithmetic Operator  Addition : 2 + 4 = 6 Subtraction : 2 - 4 = -2 Multiplication : 2 * 4 = 8 Division : 2 / 4 = 0 Modulus (remainder operator, used only with integer values) : 7 % 2 = 1 2. Increment (++) / Decrement (--) Operator Increment Operator increases its operand value by 1 while decrement operator decreases its operand value by 1.  They both have two types : Prefix : First it will increase (or decrease) the operand value by one and then participate in the operation. Postfix : First it will participate in the operation and then increase (or decrease) the operand value by 1. 3. Relational Operator They determine the relation among different operands. But they do not work with strings. 6 types of relational operator are: > greater than < less than >= greater than or equals to <= less than or equals to == equal to != not equ...

WAP to accept number of seconds from the user and convert it into number of hours, minutes and seconds

 

WAP to swap two values without using any third value

Cascading of I/O operator

  Cascading of Output Operator If we use output operator '<<' (aka stream insertion operator or put to operator) multiple times in a single 'cout' statement then it is called cascading of output operator. It can be done 255 times max. Cascading of Input Operator If we use input operator '>>' (aka stream extraction operator or get from operator) multiple times in a single 'cin' statement then it is called cascading of input operator. 

Data Type Modifiers

 As the name suggests, data type modifiers are used with fundamental data types to modify the length of data that a particular data type can hold. Following 4 datatype modifiers are available in C++: Signed Unsigned Short Long

Data Types

Datatype defines the type of value which we store in the variable.  They are a means to define the type of data and associated operation of handling it. There are 3 major data types: Fundamental Datatype : The datatypes which are not composed of other datatype are called as fundamental datatypes. Example: Integer Character Floating Point Double Floating Point Boolean Void Derived Datatype The datatypes derived from the fundamental datatypes are called as derived datatypes. Example: Function Array Pointer Reference User-defined Datatype These are defined by the user itself. Example: Class Structure Union Enumeration Typedef enum (enumeration) Enumerated means that all values are listed. Example :  Instead of writing 3 integer constants separately like : const int START = 0; const int PAUSE = 1; const int GO = 2; We can write : enum { START, PAUSE, GO} ; enum week_days { sun, mon, tue, wed, thur, fri, sat } ;                     ...

Rules for naming convention of a variable :

1. First letter of a variable name cannot be a digit. Example :  5 id  ✖ id5   ✔ i5d   ✔ 2. Special characters are not allowed within the variable name except an underscore _ Example: rollno.    ✖    //full stop is not allowed roll no    ✖   //space is not allowed _rollno   ✔ 3. Keywords are not allowed within the variable name Example :  void   ✖      

Variables / Identifiers / Literals (Constants)

Variables These are the memory location which can store a value. As the name suggests, the value of a variable can vary during the whole program. In other words, variables are named storage locations whose value can be manipulated during program run. Example:  a = 5;  ✔ 5 = a;  ✖ a = a + 2; a = a + 10; Identifiers Name of variable, function, array, class etc created by the programmer are called as identifiers. Constants Data items that never change their value during a program run. integer constant character constant floating constant string-literal