Introduction to Programming - CS201 Spring 2003 Assignment 08

By    


Assignment No. 8


Deadline


Your assignment must be uploaded/submitted before or on 13th May 2003

Uploading instructions


Please view the assignment submission processdocument provided to you by the Virtual University to upload the assignment.

 

Rules for Marking


It should be clear that your assignment will not get any credit if:

o                   The assignment is submitted after due date
o                   The submitted assignment does not compile or run
o                   The assignment is copied


Objective


The objective of this assignment is to provide hands on experience of:

  • Utilizing Structures in C.
  • Allocating memory dynamically in C.
  • Making your own header file and using it in your .cpp files..
  • Using Parameterized macros in C.
  • File handling mechanism in C.


Assignment

Write a C program that allow the user to enter employees data and calculate the total amount of salaries of all the employees whose data is entered. Your program should ask the user about the number of Employee Records he/she want to enter. After taking input from the user your program should dynamically allocate the memoryfor the number of Employee Records entered and calculate Total Net Pay Of All Employees and Also save all records in a File.







The Structure of Employee Record should have the following attributes.

1: Employee ID.
2: Employee Name.
3: Employee salary.
4: Employee net pay.

 In your code you should use
  • File handling mechanism,
    • Open/create a file
    • Write/append data to the opened file
    • Close the file 



For each Employee Record your program should take Employee ID, Employee Name and Employee Salary from the keyboard. You can calculate Net Payfor each employee by using the following formula.

          Net Pay = employee salary –Tax
          where
                     Tax        = 5% of Employee Salary

Use Parameterized Macronamed net Pay. This Macro should use the above formula and it should take two parameters Employee Salary and Tax and calculates the Net Pay.

Your output on the screen should be like:

Please enter the number of Records you want to enter     :   2


Employee ID#                 :        0026
Employee Name              :        Ali
Employee Salary             :         5000

Employee ID#                 :        0027
Employee Name              :        Shan
Employee Salary             :         5500


Total Net Pay Of All Employees     :  9975

Press any key to continue……..



  Declare yourstructure named Employee in a header file and then include this header file in your .cpp file 



How you can create your own header file:

Create a folder with a name  Assignment6

Open your Dev c++ and write your header file


Example to create your HEADER FILE:

int square(int x)
{
      return  x*x;   

}
The above code is just an example you should write structure instead of a function.

After writing the structures in the header file, save this file in a folder “Assignment6” as  myHeaderFile.h, You can also compile the program to check errors..


Suppose if you create the folder “Assignment6” in Drive D:

The path will be “D:\Assignment6\myHeaderFile.h”.

o       Now write your .cpp file
o       Your .cpp and myHeaderFile.h should be saved in the same Folder.

Example to explain how you can include your header file in .cpp file

#include <iostream.h>
#include <conio.c>
#include “myHeaderFile.h”


void main(void)
{
     cout << square(4);

    getch();
}
The above code is just an example you should use structure instead of a function


Save your .cpp  file as Assign6 in folder Assignment6

The path will be “D:\Assignment6\Assign6.cpp”.


The difference between including the file in quotation marks and angle brackets

  • When we include the file in angle brackets like #include <myHeaderFile.h>, the compiler looks in a specify directory specified in Dev-Cpp IDE include directories option.
  • When we use quotation marks like #include “myHeaderFile.h”, the compiler look into the current working directory


Assignment submission instructions:

Submit  both .cpp and .h files.

You should zip your .h(header file) and .cpp files as Assignment.zip andupload it.