CS13002 Programming and Data Structures

(Autumn semester)    Section A

Assignment Set - 2

Please write your Roll Number, Name and Assignment Number at the header of each program.


Assignment 2.a:        Filename: a2a.c

DNA sequences are made up of four characters, namely A, T, G and C. Write a program that reads a DNA sequence terminated by the character X from a file a2a.in and counts the number of occurrences of the sequence ATATACA in the given DNA. You should construct an automaton (by hand) that accepts the string ATATACA, and then implement the matching programming using a case statement that simulates the automaton.

Input File: a2a.in    (Download this file by a right-click on the filename and save as a file with the same name)

The mechanism of constructing the automaton and implementing it will be discussed in the tutorial class.

The file can be opened and read as follows:

FILE fopen( ), *fp;
char next;

/* The following line opens the file and positions the file pointer on the first character */
if ( ( fp = fopen( "a2a.in",  "r" ) ) < 0)
        { printf("Could not open file a2a.in. Quitting program\n"); exit(0); }
------
------
fscanf( fp, "%c", &next ) ;  
/* Reads the present character into next and moves the file pointer to next character */
------
------
fclose( fp );  
 /* Close the file at the very end */


Assignment 2.b:        Filename: a2b.c

In this assignment you will develop a program that computes the Semester Grade Point Average (SGPA) of a class of students and some statistics on the distribution of SGPAs. Let us assume that each student takes 5 subjects in that semester having the following credits:

Subject 1:    6 credits
Subject 2:    4 credits
Subject 3:    3 credits
Subject 4:    3 credits
Subject 5:    2 credits 

Your program should perform the following steps:

(a) It should read the number of students, N

(b) For each of the N students, it will read the grades obtained in each of the 5 subjects in the same order and print the SGPA of the student.
     The SGPA is computed as follows:

Grade Grade-Point

Ex

10
A 9
B 8
C 7
D 6
P 5
F 0

The SGPA for a set of p subjects is calculated as: 

  (Si=1..p cigi) / ( Si=1..p ci )

where ci is the number of credits of subject-i and gi is the grade point carried by the letter grade awarded to the student in that subject-i

(c) After printing the individual SGPAs, your program should print the mean (average) SGPA of the N students

(d) Finally your program should print the standard deviation of the SGPAs of the N students


Course home