Thursday, 13 September 2012

CFC OCT/NOV-2012


C-09-CM/IT-105
3025
BOARD DIPLOMA EXAMINATION, (C-09)
OCT/NOV-2012
DCME-FIRST YEAR EXAMINATION
COMPUTER FUNDAMENTALS AND PROGRAMMING IN C
Time: 3 hours]                   [Total Marks:80
PART-A
Instructions: (1) Answer all questions
(2) Each question carries three marks.
(3) Answers should be brief and straight to the point and shall not exceed five simple sentences.
1.       List different types of output devices.
2.       Define each of the following terms: (a) terabyte (b) Megabyte (c) Gigabyte
3.       How would you change the appearance of a desktop in windows?
4.       List different types of web search engines.
5.       Draw a flowchart to convert the given Fahrenheit temperature to Centigrade temperature.
6.       Differentiate between break and continue statements
7.       Define an array
8.       Differentiate between address and dereferencing operators
9.       What is structure variable?
10.   What is the use of fopen()?
PART-B
Instructions: (1) Answer any five questions.
(2) Each question carries ten marks.
(3) Answers should be comprehensive and the criteria for valuation is the content but not the length of the answer
11.   (a) convert the binary number 100101 to equivalent decimal number (b) convert the binary number 101101.101 to equivalent decimal number.
12.   (a) Explain about DIR, CD command with all options in DOS. (b) explain COPY and DELETE commands in DOS.
13.   Explain the role of a modem in accessing the internet with neat sketch.
14.   Write a c program to find the largest among four given numbers.
15.   Explain data types in c with examples along with their sizes.
16.   Write a c program to check whether the given string is palindrome or not.
17.   (a) define a function. Write the uses of function (b) Explain return statement with example
18.   (a) Write a c program using pointer to compute the sum of all elements stored in an array.
                                                     
                                                          ANSWERS:

PART-A

1. Output devices~
Out put devices are used to show the output or result on the screen.
Ex~
·         Printer.
·         Monitor.
·         Speakers.

PART-B
Explain the role of a modem in accessing the internet with neat sketch.
13 ANS:



Modem stands for Modulator/Demodulator.
·         Modems are used to connect the computer to the telephone lines.
·         Standard telephone lines transmit analog signals in which sound is translated into electrical current.
·         As a result, you need a modem to translate data into a form that can be sent over telephone lines.
·         Modem converts the in coming digital signals into analog from and sends the data to the computers.
Modem plays the very important role in exchange data between computers via a telephone line.



Tuesday, 1 May 2012

Files in C

Files in C
A file is a collection of records stored on a secondary storage device.  The collection of bytes may be interpreted(translated), for example, as characters, words, lines, paragraphs and pages from a text document; fields and records belonging to a database; or pixels from a graphical image. 
types of files
1. Text files
2. Binary files
Text Files

A text file can be a stream of characters that a computer can process sequentially. It is not only processed sequentially but only in forward direction. For this reason a text file is usually opened for only one kind of operation (reading, writing, or appending) at any given time.
Binary Files
A binary file is no different to a text file. It is a collection of bytes. In C Programming Language a byte and a character are equivalent. No special processing of the data occurs and each byte of data is transferred to or from the disk unprocessed. C Programming Language places no constructs on the file, and it may be read from, or written to, in any manner chosen by the programmer.


predefined functions in files

Function Name                     meaning
fopen()                              Creates a new file. Opens an existing file.
fclose                                Closes a file already opened file
getc()                                Reads each character from a file
putc()                                Writes each character into a file
fprintf()                              Writes the data into a file
fscanf()                             Reads data from a file
getw()                              Reads a integer from a file
putw()                             Writes an integer value into the file
fseek()                             Sets the position to a desired point in the file
ftell()                               Gives the current position in the file
rewind()                            Sets the position to the beginning of the file


Example
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char c;
myfile = fopen("raj.txt", "r");
if (fp == NULL) 

{
  printf("File doesn't exist\n");

else 
{
 do 

 {
  c = getc(fp);

putchar(c);

} while (c != EOF);

}
fclose(fp);
getch();

return(0);
}


//coying from one file to another file

#include<stdio.h>
#include<conio.h>
void main()
{
  FILE *p,*q;
  char f1[20],f2[20];
  char ch;
  printf("\nEnter the source file name to be copied:");
  gets(f1);
  p=fopen(f1,"r");
  if(p==NULL)
  {
      printf("cannot open %s",f1);
      exit(0);
  }
  printf("\nEnter the destination file name:");
  gets(f2);
  q=fopen(f2,"w");
  if(q==NULL){
      printf("cannot open %s",f2);
      exit(0);
  }
  while((ch=getc(p))!=EOF)
      putc(ch,q);
  printf("\nCOMPLETED");
  fclose(p);
  fclose(q);

}


1. Write a c program to open a file and write some text and close its.
2.  Write a c program to delete a file.
3. Write a c program to copy a file from one location to other location.
4. Write a c program to copy a data of file to other file.
5. Write a c program which display source code as a output.
6. Write a c program which writes string in the file.
7. Write a c program which reads string from file.
8. Write a c program which writes array in the file.
9. Write a c program which concatenate two file and write it third file.
10. Write a c program to find out size of any file.
11. Write a c program to know type of file.
12. Write a c program to know permission of any file.
13. Write a c program to know last date of modification of any file.
14. Write a c program to find size and drive of any file.
15. Big list of c program examples
pointers
Programs on files
c programs






Monday, 30 April 2012

Bit Field


In addition to declarators for members of a structure or union, a structure declarator can also be a specified number of bits, called a "bit field." Its length is set off from the declarator for the field name by a colon. A bit field is interpreted as an integral type.
Although languages such as C or C++ have built-in support for bit fields, these can be still implemented manually, even in languages lacking native bit field native bitfield support. It suffices to have a set of integer constants, to which each a power of two is assigned, that semantically associates each individual bit with its respective semantic state.
struct-declarator:
declarator
type-specifier declarator opt constant-expression
The constant-expression specifies the width of the field in bits. The type-specifier for the declarator must be unsigned intsigned int, or int, and the constant-expression must be a nonnegative integer value. If the value is zero, the declaration has no declarator.


You may like the following posts:
User Defined Data types:

         Enum or Enumerations

Thursday, 5 April 2012

3 rd Unit Test Papers


Third unit test
Set-1
Section a
1.       Define function? Explain the use of return statement?
Ans:
The return statement is used for two purposed, they are:
·         To return a value to the calling function.
Syntax: return(expression);
Ex: 1)return(c); //returning a variable
      2) return(x+y); //returning the expression ie.addition of variables x +y
To return the control back to the calling the function
Syntax: return;

1.       A return statement can appear any where in the function
2.       A function can have no of return statements in the function but one return statement  can be executed
3.       A return statement can return only one value at a time
2.       Write any difference b/w address & dereferencing operators?
3.       What is structure explain with an example?
Section b
4.       Explain various types of function with example programs?
5.       Explain about various dynamic memory management functions?
6.       What is recursion? Write a program to find the factorial of a given number using recursion?
                                               Set-2
1.       Distinguish between actual and formal parameters?
Ans:

     Actual parameters
      Formal parameters
     1.       The parameters specified in the function call are called as actual parameters
     The parameters specified in the function declaration are called formal parameters
    2.       Sending the value or variable or expression from the function call
Receiving the value or variable from the actual parameters
    3.       Ex: swap(a,b); or swap(2,3);
     Here a,b or 2,3 are actual parameters
Ex: void swap(int a, int b)
      {
      }
Here a,b are formal parameters
     4.       Passing the parameters a,b to swap()
Here a,b are receiving the value or variables
     5.       Actual parameters may be variable,value or expression, or structure,address
It must be variable or structure or array but not values or expressions
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
ans:
       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?

Friday, 16 March 2012

Functions


Definition
Features of functions
Types of functions
Syntax
Category of Functions

Functions Definition:

It is a collection of executable statements which performs a specific operation is called functions

Features of Functions:
  • We can achieve Modularity by using functions. Modularity means Process of taking a larger problem (software or program), understanding it, and then breaking it into smaller, more manageable parts.
  • Each part, called a module (task i.e function), has its own well-refined task.
  • All modules work through a central module, called main.
  • Reusability Code.
Types of functions:

1. Predefined Functions (Library Functions or Built-in Functions)
2. User Defined Function




Predefined functions are provided by the system (at the time of C software installation will be available automatically) and available in Library.

Ex: scanf(), printf(), sqrt(),exit(0),...

How to use Predefined Functions in your program?
Include appropriate header files before calling the functions.
Ex:
#include<stdio.h> //this is header
void main()
{
 printf("I'm predefined function\n");
}


double sqrt(double) ;

present in <math.h> that computes the square root of the argument passed to it.

2. User Defined Function:

Now we are talking about the user defined functions. Which is defined by the user or programmer is called user defined function.

Parts of a function

1. Function Declaration or Function Prototype
2. Function Definition
3. Function Call

1. Function Declaration or Function Prototype

Syntax (or) Function defination:

return_type  function_name(arguments (optional))
{
  //body of the function
  statements;
  statements;
  return statement; //optional
}

Ex:
int add(int a,int b)
{
  int c;
  c=a+b;
  return(c);
}

3. Function Call:

void main()
{
 int add(int,int);
 int a,b,c;
 a=2;
 b=3;
 c=add(a,b); //calling function
 printf("c=%d\n",c);
}

There are two ways of calling the function or
Communication with Function:

When we are calling the function, we can pass (send) arguments or parameters in function call to the function definition in two ways:

1. Call by Value 
2. Call by Reference

Call By Value:

Actual parameters are to the function. Whatever the modifications are done in function, those changes are not reflects in calling function.

Ex: add(a,b);
Example Program:
void main()
{
 int add(int,int);
 int a,b,c;
 a=2;
 b=3;
 c=add(a,b); //calling function
 printf("c=%d\n",c);
}
int add(int a,int b)
{
  int c;
  c=a+b;
  return(c);
}

Call By Reference:

Addresses of the parameters are copied to the function. Whatever the modifications are done in function, those changes are reflects in calling function.

Use & (ampersand) operator is used in the actual parameter.
Advantages of the call by reference we can send more than one value from the function to calling function.

Ex: swap(&a,&b);

Example Program:
void main()
{
 void swap(int *,int*);
int a,b;
a=2;
b=3;
swap(&a,&b);
printf("a=%d\nb=%d\n",a,b);
}
void swap(int *x,int *y)
{
 int temp=x;
 x=y;
 y=temp;
}




Interview Questions

Is it possible to execute code even after the program exits the main() function?              
What is the difference between the functions rand(),random(),srand() and randomize()?           
How to see return value of main function?         
How do we get Square root of any number Without using sqrt() function?          
Write a Program to convert decimal to binary no.             
Can you use the function fprintf()to display the output on the screen? 
What is a static function?             
How to print a statement without using printf() in c?      
How would you use bsearch()function to search a name stored in array of pointers to string?    
Does there exist any other function which can be used to convert an integer or a float to a string          
Have you heard of "mutable" keyword?              
What is an argument ? differentiate between formal arguments and actual arguments?               
Differentiate between a linker and linkage?       
Is using exit() the same as using return?               
Why should I prototype a function?       
What is meant by malloc function           
How can send unlimited no of arguments to a function, eg printf function can take any no of arguments              
What is the purpose of main( ) function?             
How would you use the functions randomize()and random()?   
How to convert decimal to octal and hexadecimal in c program?