CSI 250L Lab 5, Spring 2012

American University of Science and Technology · Programming II Lab · 2 pages · Dr. Saeed Raheel

All CSI 250L files
CSI 250L Lab 5, Spring 2012, page 1

Stuck on a question? A tutor can walk you through it.

CSI 250L Lab 5, Spring 2012, page 2

More CSI 250L files

Show the text of this lab
American University of Science & Technology Department Of Computer Science CSI 250L – Computer Programming-II Lab Spring 2011/2012 Lab Work 5 Problem1: Trace the following program: a- #include <cstring> #include <iostream> using namespace std; class Employee {private: char * name; double salary; public: Employee ( char * = "unkown", double = 466.66 ); void print(); double calculateSalary(); }; Employee::Employee ( char * n, double s ) {int a = strlen ( n ); name = new char [ a + 1 ]; strcpy ( name, n ); if ( s >= 466.66 ) salary = s; else salary = s; } doubleEmployee::calculateSalary() {if ( salary < 1000.0 ) return salary - salary * 0.02; else return salary - salary * 0.05; } void Employee::print() {cout << "Name = " << name << "\nSalary = " <<calculateSalary()<< endl; } int main() {Employee e1; e1.print(); Employee e2 ( "ABC", 1200.0 ); e2.print(); system ("pause" ); return 0; 1 Problem 2 : Create a Polygon class that stores the Cartesian coordinates of four points.  The constructor accepts four sets of coordinates and verifies that each of these is in the first quadrant with no single x- or y-coordinate larger than 20.0. These coordinates should be stored in private data members.  Provide set, get and print functions. Problem 3 : Write the class definitions and implementations for the following class specifications. Use separate files for the definition and implementation. Staff Attributes  ID: an integer to identify each staff.  fname: a string of characters( dynamic allocation).  lname: a string of characters( dynamic allocation).  rank: an integer to classify a staff position. (1,2,3)  BS: a double value for a staff basic salary. Methods  Constructor(default values)  print: a constant function, to print the information about a staff.  Provide set and get functions.  Calculate _salary: compute an employee salary by deducting a tax from the basic salary depending on the rank as follows: 1. for rank 1 a tax of 5% is deducted. 2. for rank 2 a tax of 7% is deducted. 3. for rank 3 a tax of 10% is deducted Write a driver program to create N objects of the class staff and display a menu to do the following: 1. Display a sorted list with respect to staff names. 2. Calculate the total staff salaries. 3. Output the number of staff of rank 1 2