UNIT 1 UNIT 2 UNIT 3 UNIT 4 UNIT 5 UNIT 6 UNIT 7 UNIT 8
Home Online Quiz Lab Programs Previous Questions Resources Glossary Syllabus Faculty Team

Latest News

Lesson PPTs have been uploaded to Resources Section.


Teaching material,Tutorials and Practice problems of all UNIT's are added.


ebooks have been uploaded to Resources Section.



UNIT 5


TOPICS TO BE COVERED IN THIS UNIT:

  1. Input and output - concept of a file
  2. Text files and binary files
  3. Streams
  4. Standard I/O
  5. Formatted I/O
  6. File I/O operations
  7. Error handling


TEACHING MATERIAL

Unit 5 Teaching Aids - Click Here


TUTORIAL MATERIAL

Tutorial 1


  1. What are the different modes in which a file can be opened.
  2. What is a binary file and explain its different modes.
  3. Explain the syntax of the following i/o operations.
    1. fopen
    2. fprintf
    3. ftell
    4. rewind
  4. Explain the differences between the following codes relating to their outputs.
    main                                                          main
    {			                                	{
    FILE fp;                                                         FILE fp;
    char c;                                                          char c;
    printf("enter a string:");                             printf("enter the string");
    scanf("%c",&c);                                    scanf("%c",&c);
    fp=fopen("abc","w");                         fp=fopen("abc","a");
    fprintf(fp,"%c",c);                                    fprintf(fp,"%c",c);
    fclose(fp);                                                      fclose(fp);
    }                                                               }
    
  5. The return type of the function fopen is?______
  6. In the following code,what is the work of argc and argv
    main(int argc,char *argv[])
    	{
    	------
    	------
    	}
    

Tutorial 2


  1. Describe the error handling techniques used in i/o operations
  2. Write a program to write your details into file and print them
  3. Observe the following code
    	main()
    	{
    	int i;
    	for(i=1;i=10;i++)
    	printf("%d",i);
    	}
          after execution of the above program print.c we get print.exe
        if we perform the command "c:\>print.exe>abc.txt"
    
    1. what does '>' operator do.
    2. what is the data present in abc.txt
  4. if a file contains the following text{ABCDEFGHIJKLMNOPQRSTUVWXYZ^Z}then what is the output for
    	
    	fseek(fp,5l,0);
    	printf("The position of %c is %d",getc(fp),ftell(fp));
    
  5. If the same file is taken as input,then what is the output for
    	fseek(fp,10,SEEK_SET);
    	if(feof(fp2)!=0)
    	printf("File is run out of data");
    	else
    	printf("%c",fgetc(fp));
    
    

PRACTICE PROBLEMS

Beginner Problems


  1. What do you mean by sorting? Mention the different types of sorting.
  2. Explain linear search with a good example.
  3. What is the time complexity of binary search?
  4. Trace out all passes and steps by hand to sort the following list in bubble sort
            5    2   1   8   7
  5. Write algorithm for performing selection sort.
  6. Write a program to sort elements of an array using Insertion sort.

Intermediate Problems


  1. Formulate recursive algorithm for binary search with its timing analysis.
  2. Write a program to explain selection sort. Which type of technique does it belong?
  3. Compare the advantage and disadvantage of bubble, insertion and selection sort.
  4. Sort the following numbers using selection sort and give the required steps.
    		96,31,27,42,34,76,61,10,4
    1. Distinguish between linear and binary search methods.
    2. Write an algorithm for non-recursive binary search method.
  5. Write an algorithm for two-way merge sort. Analyze its time complexity.
  6. Derive the time complexity of merge sort.
    1. Explain Quick sort with algorithm.
    2. Analyze the worst case performance of Quick sort and compare with Selection sort.

Advanced Problems



  1. Write a program to sort the elements whose worst case is O (n2) and average case is
               O (n log n).
  2. Write an algorithm for routine merge(x, lb1, ub1, ub2) that assumes that
    x [lb1] through x [ub1] and x[ub1 + 1] through x[ub2] are sorted and merges the two into x[lb1] through x[ub2].
  3. Trace through the steps by hand to sort the following list in Quick sort.
    		28 7 39 3 63 13 61 17 50 21
  4. Write in detail about the following:
    1. Selection sort
    2. Merge Sort.
  5. Suppose that the list contains the integers 3 7 13 17 28 50 21 39 61 63 in this order.
    Trace through the steps of binary search to determine what comparisons of keys are done in searching.
    1. To locate 17
    2. To locate 16
  6. Write an algorithm for performing selection sort when the input elements are represented as a linked list.
  7. Write about Sorting Efficiency, and explain O - notation Analysis.

This Page Is Designed By R.Harish

Copyright (c) Aditya Engineering Colleges, Surampalem. All rights reserved.
Development Team