Sunday 27 March 2011

User Defined Data Types


Enumerations (enum)

Enumerations create new data types to contain something different that is not limited to the values fundamental
data types may take. Its form is the following: 

Syntax:
enum identifier{data1,data2,data3,..};

enum is ” Enumerated Data Type “.
enum is user defined data type
In the above example “identifier” is nothing but the user defined data type.

data1,data2,data3….. etc creates one set of enum values.

Using “identifier” we are creating our variables.


enum enumeration_name {
  value1,
  value2,
  value3,
 . 
 . 
} object_names;


enum month {JAN,FEB,MAR,APR};
enum month m;

First Line Creates “User Defined Data Type” called month.
It has 12 values as given in the pair of braces.
In the second line “m” variable is declared of type “month” which can be initialized with any “data value amongst 4 values”.
m = FEB;
Default Numeric value assigned to first enum value is “0”.
Numerically JAN is given value “0”.
FEB is given value “1”.
MAR is given value “2”.
APR is given value “3”.

printf("%d",m);
It will Print “1” on the screen because “Numerical Equivalent” of  “FEB” is 1 and “rmonth” is initialized by “FEB”.


Generally Printing Value of enum variable is as good as printing “Integer“.


You may like the following posts:

Tuesday 15 March 2011

INTERNAL AND EXTERNAL LAB EXAM PAPER

                                         External and Internal Question Paper for CFC CM-106

  1. (a) wap to find out whether the given no is prime or not?                                                               (b) Procedure for installing Software
  2. (a) wap to print Fibonacci series                                                                                     (b)procedure for installing Hardware
  3. (a)wap to find out factorial of a given number?                                                                            (b) wap to find whether the given year is leap year or not?
  4. (a) transpose of a matrix                                                                                          (b) wap to find the given no is even or odd
  5. (a) wap to find out whether the given no is palindrome or not?                                                      (b) wap to find the given year is leap year or not?
  6. Explain about call by value and call by reference
  7. (a) wap to find the sum of given two matrices                                                                             (b) c program on quadratic equation by using switch statement
  8. (a) wap to find factorial of a given no using ‘Recursion’ function
  9. (a) wap to print reverse of an array                                                                                           (b)wap to demonstrate ‘type casting’.
  10. wap to find prime or not?
  11. Matrix multiplication or product of a matrix or Matrix multiplication 
  12. (a) wap to illustrate all the ‘string handling’ functions                                                               (b)wap to demonstrate on 2d array
  13. (a) How to write, compile, execute the c program with a simple c program                                (b) wap to convert Fahrenheit to celcious
  14. (a) wap to find sum of n natural no’s
  15. (a) wap to find avg of the 3 subjects using structures                                                                 (b)how do you find the size of the structure
  16. (a)wap to find out the largest of 2 no’s using conditional operators.
  17. (a) wap to factorial using recursion function                                                                                 (b) wap to find even no or odd
  18. (a) wap to find leap year or not?                                                                             (b) wap to find the sum of given two matrices

UNIT TEST QUESTION PAPERS

SET- 1
STATE BOARD OF TECHNICAL EDUCATION & TRAINING :: HYDERABAD
COMPUTER FUNDAMENTALS AND PROGRAMMING IN C
UNIT TEST-I
Time: 1 Hour                                                       Max.Marks:20
PART-A                                                            3*2=6 marks
I. Answer All the question. Each question carries 2 marks
1. List different types of I/O used in a Computer.
2. convert the following: (a) (502)10 to (     ) 16   
(b)(10101)2 to (     ) 8   
3. What is the need of an operating system in computer.
PART-B
II. Answer any Two question. Each question carries 7 marks    2*7=14 marks
4. Explain in brief the generations of Computer.
5. Explain about any four DOS internal commands.
6. (a) What is meant by defragmentation? 3 marks
    (b) Write the procedure to install a Hardware using control panel? 4 marks
SET -2

TRR COLLEGE OF TECHNOLOGY(POLYTECHNIC)
UNIT TEST-1  YEAR 2011                                                                MAX MARKS 20
SEMESTER YEAR: 1 YEAR                                               TIME 1 HOUR
SUBJECT CODE AND NAME: CM-105:CFOA
SECTION-A                                                          3*2=6
ANSWER ALL QUESTIONS
1.       Different types of input/output devices in a computer
2.       Convert the following (a) (502)10 to  ( )16 (b) (10101)2 to ( )8
(a) What is the need of Operating System? (b) define the term (i) WAN (ii) FTP (iv) WWW



SECTION-B                          2*7=14
ANSWER ANY TWO QUESTIONS
Essay Questions  each question carries 7 marks
1.       Explain briefly about generation of computer
2.       Explain any DOS Internal and External commands
(a) What is Defragmentation (b) write the procedure to install a hardware using control panel


Ans:


Answers all the questions

1) Lists the different types of input/output devices in a computer?
Ans: Input devices:

a)key board
b) Mouse
c) joy stick
d) track ball

Output devices:

a)printer
b) Monitor
c) Speakers and etc……
3) Explain the terms:
a) WAN: Wide area net work
b)FTP: File transfer protocol
c) TELNET: tale communication
d)www: World wide web
                                                            Section-B
4) a) Describe the installing of new software using control panel ?
Control panel is parts of a micro soft windows graphical user inter face.
 Control panel allows users to view and modify the system settings to control panel and devices of the system
Steps :
·                     click on the start button & go to the control panel
·                     Click on add or remove programs option then it will display the 3 basic options  on lift side of the picture them click on add new programs then there will display two options.
i.e. a) Adding programs from cd-rom pr floppy:
if the program  we want to install us on a CD-ROM or on a floppy disk on the CD or FLOPPY button and a screen will appear us at introduce the CD or FLOPPY in the corresponding drive normally it will ask a questions regarding where the programs is to be installed we recommend to accept the folder  that is suggest
this is a one way to install a program a CD but in the majority of the cases it is not necessary, it is easier and  quicker to just put the CD un and let the program in the CD drive it do it automatically. The result is the same and we will save ourselves having to reach this screen to add new programs.

b) write difference between dos and windows
Dos
Windows
1)it is a CUI
1)it is a GUI
2) it allows the only a single task
2)it allows multi tasks
3) we need to remember commands
3)we don’t want to remember commands
4)it us not possible to share the data
4)it is possible to share the data
5)memory management is easy
5)it is difficult
6)it allows single users
6)it allows multi users
7)size is small
7)size is large

5)a) what is defragmentation?

Defragmentation is  defined as the organizing  the disc space in proper manner.
b) Write the procedure to install a hard ware using control panel
The assistant searches for new hardware. Normally it will not find anything new. Now it asks if we have already connected the new hardware if we answer NO a screen will appear indicating the assistant has finalized or ended since there is nothing to detect.
The hardware that we want to install will probably not be on list show. the list to find a line that says “add new programs” and click on this line. Then click next.
There are two options
The first one is to have the windows look again for new hardware. Nevertheless, we can try again and we will get the screen that is shown here.
Press the next button untells you get Finish button. Then the new hardware will be  installed.
  









SET-3

UNIT TEST-1  YEAR 2011                                                                MAX MARKS 20
SEMESTER YEAR: 1 YEAR                                               TIME 1 HOUR
SUBJECT CODE AND NAME: CM-105:CFOA
SECTION-A                                                          3*2=6
ANSWER ALL QUESTIONS

1.       State the importance of cache memory
2.       What is the need of Operating System
3.       Explain the term (a) WAN (b) FTP (C) TELNET (d) URL (e) WWW
SECTION-B                          2*7=14
ANSWER ANY TWO QUESTIONS
Essay Questions  each question carries 7 marks

1.       Convert the following: (a) (49B5)16 to ( )10 (b) (60.3a)16 to ( )2 (c) (137A)16 to ( )2
2.       (a) describe the Installing of new software using control panel (b) defference between DOS & WINDOWS
3.       (a) compare LAN & WAN (B) state the advantages of Internet

UNIT TEST-2
TRR COLLEGE OF TECHNOLOGY(POLYTECHNIC)
UNIT TEST II/YEAR 2010                                             MAXIMUM MARKS:20
SEMESTER/YEAR: 1 YEAR                                          Time: 1 Hour
SUBJECT CODE & name: cm-105:CFOA
SECTION-A                                  3*2=6
ANSWER ALL QUESTIONS:
1. Define URL?
2. Draw A Flow Char On Largest Of 3 Numbers
3.What is preprocessor directives & Macros ? with example.


section-b    2*7=14 marks
answer any two questions:
4. describe the different internet connection methods.
5. (a) Explain the data types in C with examples.
    (b)Write the syntax of (i) if (ii) if-else (iii) nested if
6. (a) write a program for even or odd number
    (b)write a program to find the year is leap year or not?




                                                        UNIT TEST -II
                                                     CME FIRST YEAR
1)           wap test the given no is palindrome or not?
2)           wap to find the given no is prime number or not?
3)           Wap to display the following format using nesting loops
4)           *
5)           **
6)           ***
7)           Write the syntax for nested for loop?
8)           Difference between structure and unions and arrays
9)           Define string?List various string handling functions
10)       Define array?declaration&initialization of 1d and 2d arrays
11)       Define POINTER? Advantages of POINTERS
12)       Define syntax, flowchart, of following loop
(i)while (ii)do..while loop (iii)for loop
13)       Wap on matrix multiplication of 2 matrix
Wap to display the factorial no
/*factorial of a given no*/




QUESTIONS FOR 2ND UNIT TEST (29-03-2010)

1.)Define an Array. Write declaration and initialization of 1D and 2D array.
2.)define strings, list out various string functions
3)define structure and union.

Long questions
1) (a)wap to demonstrate the following o/p
 *
**
***
b)write the syntax for nested for loop.
2)write a c program to multiply of two matrices
3)explain about the following with flow charts , syntax and also give examples:
a) for loop (b)while loop (c)do..while loop

second set

1)what are the escape sequences in c?
2)what are the bitwise operators
3)define array?give declaration & initialization of 1d and 2d array
4)differentiation b/w break and continue
5)differentiation b/w while and do..while
6)define string? list different string handling functions (or)various string operations.
7)give definition, syntax, flowcharts for the following loops
 i)while loop (ii)do..while loop (iii)for loop.
8)what is function prototype and return statement with example
(9)define recursion? give the example
(10)differentiate between array &structure
11)diff b/w structure & union.
12)define pointer?give the advantages of pointer?

3rd set

1)write a program to check whether a given number is palindrome or not.
2)write a c program to check whether a given number is prime number or not.
3)(a)write a c program to generate to the following format:
*
**
***
(b)write a program to multiply the 2 matrices.
5)write a c program to transpose the matrix
6)wap to display Fibonacci series
7)give the definition, declaration & initialization of a structure with an example.
-----------------------------------------------------------------------------------------------------------
UNIT TEST-II SETS                                                                            
Set-I
Section- A
1)      (a) write the precedence of Operators in c language (b) List out all the operators
2)      What is the difference between keyword and Identifier  (or) Explain various loop statements(definitions, syntax, flow chart)
3)      Explain about printf() and scanf() with a simple program (or) Explain about the basic datatypes ? Write a c program using basic data types
Section B
1)      (a) List out various conditional Statement available in ‘c’ language with syntax, flow chart. (b) write an algorithm, flowchart to find out the root of the quadratic equation                                                (or)                                                                                                                                                                                       What do you mean by type conversions (type casting) ? Write a algorithm, flowchart  and program using typecasting
2)      (a) what is the difference between pre-increment and post-increment? Illustrate with example program (b) Explain about the Iterative (Looping) statements along with syntax and flowchart.
3)      (a) How do you decorate and initialize arrays and Strings with a program (b) define the following terms. (i) break (ii) continue (iii) null statement
                                                                           Answers

1.    Explain about printf() and scanf() with a program
     #include<stdio.h>
     #include<conio.h>
     void main()
    {
         int a,b,sum;
         printf("Enter the two number\n");
         scanf("%d,%d",&a,&b);
         sum=a+b;
         printf("sum of two numbers is %d",sum);
         getch();
     }
2.     Explain about basic data types? Write a program using basic data types?
There are four basic data types:-
DATA TYES                      BYTES                          RANGE
      int                                 2bytes                         -32,768 to 32767
     float                                4bytes                           3.4e-38 to 3.4e+38
     char                                1byte                             -128 to127
   double                              8bytes                           1.7e,-308 to 1.7e,+308
3.     Define constant variable and identifier and rules.
CONSTANT: 
       If we declare any variable as a constant the value of the variable will not be changed or modified.
SYNTAX:
     datatype constant variable = value;
EXAMPLE:
     int const a=10;
VARIABLES:
   A variable is a identifier. It is used to store the data. It store only one value.
SYNTAX:
     datatype variable;
EXAMPLE:
     int a;
a=10;
4.     (a). How do you declare arrays and strings , explain in a program
         An array is the collection of elements of different datatypes of homogenious data
Examples:  int a[5];// declaration an array of a type int
·        array name follows the same rules of naming variable this name can be used only to refuse the array and as an ordinary variable
SYNTAX:
   Datatype variable[size];
 
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
    int i,a[5];
    clrscr();
    for (i=0;i<2;i++)
    {
          scanf(“%d”,&a[i]);
     }
     for (i=0;i<5;i++)
     {
         Printf(“the value in a [%d] is =%d\n”,I,a[i]);
     }
    getch();
  }

     (b) Define the terms (i) break (ii) continue (iii) null statement.
          Break:
               Break statement is used in generally with loops and switch statement.       It is used to terminate a loop.
          SYNTAX:  break;
          Continue:
                 The continue statement is used for doing the next iteration.
          SYNTAX:  continue;
        Null statement:
                 Statement is always terminated by as semicolon. A semicolon with nothing preceding it is also available statement. Caused the null statement.
5.     Define an looping statement with program
     #include<stdio.h>
    #include<conio.h>
    Void main()
     {
          int n,I,flag=0;
          clrscr();
          printf(“enter no.”);
          scanf(“%d”,&n);
          for(i=2;i<n/2;i++0
          if(n%i==0)
          {
              flage=1;
              break;
          }
           if(flag==0)
          {
               printf(“no. is prime”);
          }
          else
          {
              printf(“no. is not prime”),
}
getch();
     }

6.     Explain logical operators, conditional operators? Write program using these operators.

Operator                         meaning
&&                                 logical AND
!!                                     logical or
!                                      logical NOT
Logical or operator
Conditional 1             or                                                     conditionl2           =               result
    true                                          true                       =                  true
    true                                          false                      =                  true
    false                                         true                       =                  true
    false                                         false                      =                  false
                                               !true= false
                                               !false=true
Precedence of logical operator
Operator                                   priority
!                                           higher priority
&&                                         2nd priority
||                                             3rd priority
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
    int a,b,c,d,f;
    clrscr();
     printf(“%d%d%d\n”&d,&e,&f);
           a = d>e && e>f;
           b = f>e && e>f;
           c = a>b || f>d;
     printf(“a,b,c values are %d\n %d\n %d\n”,a,b,c);
    getch();
  }









----------------------------------------------------------------------------------------------------

Set 2
Section-A:
1.       Define constant, variable and identifier and rules for identifiers.                                                                               (or)                                                        List out the escape sequences
2.       Write a program, algorithm, flow chart for even or odd numbers                                                               (or)
3.       What is preprocessor directives and macros.
4.       How do you declare and initialize strings? List out any four string-handling functions

Section-B
4)      Define all the Looping Statements and write an algorithm, flowchart and program to find out whether the given number is prime or not. ? (or)
5)      Explain about the logical operators, conditional operators ? And write any program using these operators
6)      (a) difference between while loop and ’ do..while loop (b) Write a c program, algorithm, flow chart to find out factorial of a given number                                                                                                          (or)
7)      (a) difference between if-statement and if-else (b) wap to find largest of 2 numbers                    
8)      Explain the switch statement with syntax, flow chart, program

Set-3
Section-a
1)      Explain the input/output functions with suitable examples.
2)      Write a program to swap two values.
3)      Evaluate the following expression 2*8/4+4%2+3/3+(6-3)/3 with steps
Section-b
9)      (a) what is jumping statements (unconditional statements) (b) write a program using any unconditional statements
10)   write structure of c program in detail
11)   (a) differentiate between break and continue statements (b) write any program using else if statements                                                                                                                                                                            (or)
12)   Write a c program to find the reverse of its number (example 5 to 1)
Answers:

                             Section-A
2) write a program to swap two values.

#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, temp;
clrscr();
printf(“enter the no’s\n);
scanf(“%d%d”,&a,&b);
temp=a;
a=b;
b=temp;
printf(“%d%d”,a,b);
getch();
}

4) a) what is jumping statements.
There are few types of unconditional statements
1.break
2.goto.
3.continue

break.
It is used to when the ctrl reaches the break statements . it comes out of the block
Syntax.
break;

goto.
It is used to when the statement is there control goes to label
Syntax.
 goto label;

continue.
Continue statements is used to control goes to next iteration
Syntax.
continue;
 

5) write the structure of “C” program in detail.
Documentation section
Link section
Definition section
Global section
Main() section
Sub program section
The “C” program contains the 3parts



Part-1
Documentation section .
* It contains the comment lines.
*it is optional
Link section.
  •      it contains the header files.
Ex #include<stdio.h>
     #include<conio.h>
Definition section.
  •      The definition section contains the macros.
  •      It is optional
Global section.
  •      If the variable is declared before the function then it is known as the variable
  •     Ex: int a;
                 void main()
                 {
                   statemaets………………
                }
Part-2
main()
  •      ”C” program starts from the main() section
  •      Main() contains the blog of the statements
  •      Main is the special user defined (), it is not predefined in any header files
Part-3
Sub program section.
  •      It is a user defined function

      Break
      Continue
      1) it executes the loop
      1) it continues the loop
     2)the main loop of break statements is escape from the block
     2)generally use of continue statements is to prefer next iteration of the loop
      3)syntax- break;
      3)syntax- continue;
     4)break can be used in forloop,whileloop, do whileloop and switch statements 
     4) continue can be use in for loop, while loop, do while loop but not in switch statements.
     5) it is more useful than continue
     5)it is less useful than break
  
b) write any program using else –if.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“enter the values\n”);
scanf(“%a%b%c”,&a,&b,&c);
if(a= =b&&b= =c)
{
Printf(“values are equal”);
}

else if(a>b&&a>c)
{
Printf(“a is big\n”);
}
else if(b>c)
{
Printf(b is big\n);
}
else
{
Printf(“c is big \n);
}
getch();

}third unit test question papers

Third unit test
Set-1
Section a
·         Define function? Explain the use of return statement?
     
    
·         Write any difference b/w address & dereferencing operators?
·         What is structure explain with an example?
Section b
·         Explain various types of function with example programs?
·         Explain about various dynamic memory management functions?
·         What is recursion? Write a program to find the factorial of a given number using recursion?
Set-2
2.       What is pointer? List the advantages of pointers
Ans:
1.       We can return more than one value from a function
2.       Indirect accessing
3.       It provides dynamic memory management
4.       To pass arrays and strings more conveniently from one function to another function
5.       It provides program execution speed
6.       To manipulate arrays more easily by moving pointers to them instead of moving the arrays themselves
3.       Differentiate between array & structure?   
Ans:
Structure
Array
1.       It is a collection of elements(variables) of different data types
1.       It is a collection of elements of same data type
2.       We have to use .(dot) operator or -> (cap) operator for accessing
2.       Subscript for accessing array elements
3.       Syntax:
struct  tag
{
  Datatype memeber1;
  Datatype member2;
  …….
};
3.       Declaration of array:
Datatype arrayname[size]={list of elements separated by comma};
4.       Example:
struct  student
{
 int rollno;
 char name[10];
 float avg;
};
Struct student stud={01,”raj\0”,90.25};
4.       int a[5]={1,2,3,4,5};

                                                                                        Section -b
4.       Explain call by value and call by reference with example programs?
5.       Explain about addressing and dereferencing operators

Address operator
Dereferencing operators
1.       Address operator is &
Ex: &a where a is a variable
Dereferencing operator is *
Example: *a where a is pointer
2.       It is used to initialize pointer variable

It is used to declare a pointer varialbe

3.       It is a unary operator
It is also unary operator
4.       It returns the address of variable
It returns the value at that address


6.       What are the various storage classes in c explain?
Set-3
1.       What is self referential structure?
2.       List various betwise operators in c?
3.       List various I/O function with files?
Section-B
4.       Explain various types of functions with example with example programs
5.       Explain about various dynamic memory management functions with examples?
6.       What is recursion? Write a c program to find factorial of a given number using recursion?