Wednesday, September 9, 2015

MCA I: Assignment 1

Q1. Write a note on history of C language.
Q2. Define the term of translators. What are the different types of translators?
Q3. Write a note on the following:
A.      Low Level language
B.      Middle Level Language
C.      High Level Language
Q4. What are the different types of operators? What do you mean by precedence and associativity of an operator? Explain the use of each using examples.
[ +,         -,             *,           /,            %,         
 =,           <,           <=,        >,            >=,         ==,         !=,         
?:,          
sizeof()
++,         --


Q5. Write a short note on Keyword, Data Type & Variable.

Thursday, September 3, 2015

sizeof operator in C (MCA I)

sizeof operator

  1. sizeof operator is used to calcualte the size of data type or variables.
  2. sizeof operator can be nested.
  3. sizeof operator will return the size in integer format.
  4. sizeof operator syntax looks more like a function but it is considered as an operator in c programming

Example of sizeof() operator

Size of Variables

#include<stdio.h>

int main() {

   int ivar = 100;
   char cvar = 'a';
   float fvar = 10.10;

   printf("%d", sizeof(ivar));
   printf("%d", sizeof(cvar));
   printf("%d", sizeof(fvar));
   return 0;
}

Operators in C Language(MCA I)

C Programming Operators :


4.1
4.2
Operator
Meaning
Example
+
Addition Operator
160 + 20 = 180
-
Subtraction Operator
60 – 10 = 50
*
Multiplication Operator
20 * 4 = 80
/
Division Operator
20 / 5 = 4
%
Modulo Operator
20 % 7 = 6
In C Programming , Unary operators are having higher priority than the other operators. Unary Operators are executed before the execution of the other operators. Increment and Decrement are the examples of the Unary operator in C.
4.3
1.      Increment operator is used to increment the current value of variable by adding integer 1.
2.     Increment operator can be applied to only variables.
3.     Increment operator is denoted by ++.

A. Pre Increment Operator

Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression.
b = ++y;
In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before using it in a expression.

B. Post Increment Operator

Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented.
b = x++;
In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5 because old value of ‘x’ is used.
4.4
We have seen increment operator in C Programming which increments the value of the variable by 1. Similarly C Supports one more unary operator i.e decrement operator which behaves like increment operator but only difference is that it decreases the value of variable by 1.
4.5
Operator
Meaning
> 
Greater than
>=
Greater than or equal to
<=
Less than or equal to
< 
Less than
4.6
Whenever we use if statement then we can use relational operator which tells us the result of the comparison, so if we want to compare more than one conditions then we need to use logical operators. Suppose we need to execute certain block of code if and only if two conditions are satisfied then we can use Logical Operator in C Programming.
Operator
Name of the Operator
&&
And Operator
||
Or Operator
!
Not Operator


4.8

Conditional Operators [ ?: ] : Ternary Operator Statement in C

1.      They are also called as Ternary Operator .
2.     They also called as ?: operator
3.     Ternary Operators takes on 3 Arguments

Syntax :

expression 1 ? expression 2 : expression 3
where
·         expression1 is Condition
·         expression2 is Statement Followed if Condition is True
·         expression2 is Statement Followed if Condition is False










Variables in C(MCA I)

Rules For Constructing Variable Name

  1. Characters Allowed :
    • Underscore(_)
    • Capital Letters ( A – Z )
    • Small Letters ( a – z )
    • Digits ( 0 – 9 )
  1. Blanks & Commas are not allowed
  2. No Special Symbols other than underscore(_) are allowed
  3. First Character should be alphabet or Underscore
  4. Variable name Should not be Reserved Word

Fundamental Attributes of C Variable :

  1. Name of a Variable
  2. Value Inside Variable
  3. Address of Variable
  4. Size of a Variable
  5. Type of a Variable

Variable Declaration ?

  • To Declare is nothing but to represent a variable.
  • Only Variable name and its Data type is Represented in Declaration.

Keywords in C language(MCA I)

Keywords in C Programming Language :

  1. Keywords are those words whose meaning is already defined by Compiler
  2. Cannot be used as Variable Name
  3. There are 32 Keywords in C
  4. C Keywords are also called as Reserved words .

32 Keywords in C Programming Language

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile

Simple Tip :

We cannot Use Keywords for – For Declaring Variable Name,For Function Name and for declaring Constant Variable

Character Set Of C Language(MCA I)

Character set of C

character:-          It denotes any alphabet, digit or special symbol used to represent information. 

Use:-                      These characters can be combined to form variables. C uses constants, variables, operators, keywords and expressions as building blocks to form a basic C program. 

Character set:-    The character set is the fundamental raw material of any language and they are used to represent information. Like natural languages, computer language will also have well defined character set, which is useful to build the programs. 

The characters in C are grouped into the following two categories:

1.      Source character set
                                a.      Alphabets
                                b.      Digits
                                c.      Special Characters
                                d.      White Spaces

2.      Execution character set
                                a.     Escape Sequence

Source character set

ALPHABETS
            Uppercase letters                 A-Z
            Lowercase letters                 a-z

DIGITS                                                  0, 1, 2, 3, 4, 5, 6, 7, 8, 9

SPECIAL CHARACTERS

 ~          tilde                            %         percent sign               |           vertical bar         @        at symbol               +          plus sign                    <          less than

_          underscore                -           minus sign                 >          greater than       ^          caret                        #          number sign              =          equal to

&         ampersand                 $          dollar sign                 /           slash                  (           left parenthesis      *          asterisk                      \           back slash

)           right parenthesis       ′           apostrophe                :           colon                  [           left bracket               "          quotation mark         ;           semicolon

]           right bracket              !           exclamation mark     ,           comma                { left flower brace               ?            Question mark       .           dot operator            

}            right flower brace     

WHITESPACE CHARACTERS

\b         blank space               \t          horizontal tab                     \r         carriage return                             \n         new line
        
\\          Back slash                 \’         Single quote                          \"         Double quote       \?         Question mark          \0         Null                            \a         Alarm (bell)

Execution Character Set

Certain ASCII characters are unprintable, which means they are not displayed on the screen or printer. Those characters perform other functions aside from displaying text. Examples are backspacing, moving to a newline, or ringing a bell. 

They are used in output statements. Escape sequence usually consists of a backslash and a letter or a combination of digits. An escape sequence is considered as a single character but a valid character constant. 

These are employed at the time of execution of the program. Execution characters set are always represented by a backslash (\) followed by a character. Note that each one of character constants represents one character, although they consist of two characters. These characters combinations are called as escape sequence.

BCA III Phase II of the termwork.

1. Write a program to show the utility of Scope Resolution Operator using suitable example
a) wrt global &local variable
b) wrt member functions of a class
Q2.Write a program to demonstrate the usage of Inline functions using suitable example. [Write a program to multiply every element of array with 4.]
Q3.Write a program to demonstrate the usage of default arguments using suitable example
Q4. WAP which uses a FRIEND function, that is friend to many classes(Topper out of girls and boys)
Q5. WAP to demonstrate a FRIEND function, that is member of one class & friend to another.
Q6. Create two classes DM and DB, which store the value of distances. DM stores distances in meters and centimeters and DB in feet and inches. Write a program that can read values for the class object and add one object of DM with another object of DB. Use a friend function to carry out the addition operation. The object that stores the results may be a DM object or DB object, depending on the units in which results are required. The display should be in the format of feet and inches or meters and centimeters depending on the object on display.
Q 7. Demonstate swap function in all the following ways
Class NUMBER
{
};
Void main()
{
Int a,b;
NUMBER N,M;
Swap(a,b)
Swap(N.i,M.i);
Swap(N,M)
N.swap(M);
N.swap();
}
Qus 8.Write a program that has two classes RUPEES & DOLLARS. Both should have relevant members. There should be a friend function that should display the total monetary value of two objects of the above classes.
Q9. Demonstrate the friend class using a suitable example.
Q10. Demonstrate the concept of Static Data Member using a suitable example.
[Define a stack uses one linear array and counter to notice number of item in stack. Define a member function corresponding to PUSH and POP operations including overflow and underflow situation relevantly. Create an object of stack class and perform these operations for that.]
Q11. Design a class ARRAY, having the functions getdata(), dispdata(), sort(),search(int n), get_frequency(int n), reverse().
Q 12. WAP that has three classes Circle, Rectangle &square with appropriate data members & member functions.write the main() in such a way that user has to enter only one value ie perimeter of Square or rectangle, or circumference. The program should have a friend function max_cvrg_area() to specify which figure has maximum coverage arean.
main()
{
Cout<<Enter the length;
Cin>>l;
Circle C;
Rect R;
SQR S;
C.getdata(l);
R.getdata(l);
S.getdata(l);
Cout<<max_cvrg_area(C,R,S);

}



NOTE:Write Question in Black ink... Solution in blue ink &  Output shuld be Printed.