Вы находитесь на странице: 1из 2

CSL100 Assignment 8: Modular Programming

[10th M ar28th Mar, 2014] 20 Marks

The objective of this exercise is to introduce modularity in our program design. The entire program is divided into dierent .cpp les and associated .h les, with each le containing a set of data declarations and/or function denitions/declarations. You will be given an input le containing marks of at most 100 students in Minor and Major examinations. Your task is to read the marks, check if they are valid, and assign a grade to each student based on the total marks. Follow the steps mentioned below. Your program will be divided into three .cpp les: grading.cpp, leio.cpp, and valid.cpp. File: grading.cpp The le declares the integer arrays for storing the input data. It also contains two function denitions. main function is present here. From main, you call the following functions, passing the appropriate arrays as parameters. Every function should read/write data from/to suitable function parameters. readle for reading input data into the respective arrays. This function is dened in leio.cpp. validate for validating the input data. This function is dened in valid.cpp. grading for assigning the grades. This function is dened in grading.cpp (same le as main ). print for printing the output grades. This function is dened in leio.cpp. Function grading is also present in grading.cpp, containing the logic for grading. The logic is as follows. Find the maximum and minimum total marks obtained by students. Divide the entire range into ve equal slabs and assign A grade to the highest slab, B to the next, and so on (C, D, and E grades). File: leio.cpp This le contains the function readle that reads the text le lemarks.txt and stores the data in the arrays. The text le lemarks.txt contains four columns of integers, with each line consisting of four numbers: Roll number (integer), Minor 1 marks, Minor 2 marks and Major marks. Any formatting errors should be reported. This le also contains the function print for printing out all the students roll numbers and associated grades into output le output.txt using ofstream and << operator. Also it prints out the slabs you computed for the grading, and the number of students in each slab. Remember to close open les after they are no longer necessary.

File: valid.cpp Every students marks need to be validated. Function validate present in this le checks the marks for validity. In case of any discrepancy, the function should print out Marks in exam X are not valid for roll no. Y and terminate. Assume that the valid range for marks are as follows. Minor 1 marks [0, 25]; Minor 2 marks [0, 25]; Major marks [0, 50]. A function f that is dened in one le A.cpp, is not visible in another le B.cpp. In order to make it visible, we employ the following protocol. We create a new le A.h and include in it the declarations of functions (such as f ) that need to be called from other les. Just copy the function header into the .h le. Note that ONLY the declaration is copied. The function denition is NOT copied. Now, insert the following statement near the top of B.cpp: #include A.h This informs the compiler about the signature of f (number and types of parameters in f , the return type, etc.) Repeat the procedure for all les whose functions are to be visible outside the le. Learn how to use g++ with -c option, to compile the .cpp les separately into the respective .o les, and to link the .o les in the nal step with another g++ invocation to generate the executable. Note: Please follow the submission guidelines mentioned on Sakai.

Вам также может понравиться