Thread: need some help?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    14

    need some help?

    hey this is my first time writting C++ code and im having a bit of trouble switching over from c. i was wondering if someone wouldnt mind having a look at my code to see if they can spot anything that seems wrong. any help would be appreciated. thanks


    employee.cpp
    Code:
    #include <iostream>
    #include <string>
    
    #include "employee.h"
    
    using namespace std;
    
    void ReadEmployees( Employee * a, int N)
    {
    
    	int i;
    
    	for(i = 0 ; i < N ; i++)
    	{
    		a[i] = CollectData();
    	}
    
    }
    
    double FindLowestSalary( Employee * a, int N)
    {
    	double low = a[0].salary; //salary of first employee
    	int i;
    
    	for(i = 0 ; i < N ; i++) 
    	{
    		if (a[i].salary <= low)
    			low = a[i].salary;
    	}
    
    	return low;
    }
    
    double FindHighestSalary(Employee * a, int N)
    {
    	double max = a[0].salary; //salary of first employee
    	int i;
    
    	for(i = 0 ; i < N ; i++) 
    	{
    		if (a[i].salary > max)
    			max = a[i].salary;
    	}
    
    	return max;
    
    }
    
    Employee CollectData()
    {
    	cout << "Entering Employee Data\n";
    	Employee * e;
    	cout << "Enter ID:  ";
    	cin >> e.ID;
    	cin.ignore();
    
    	cout << "Enter first name: ";
    	getline(cin, e.firstname);
    	cin.ignore();
    
    	cout << "Enter last name: ";
    	getline(cin, e.lastname);
    	cin.ignore();
    
    	cout << "Enter address: ";
    	getline(cin, e.address;
    	cin.ignore();
    
    	cout << "Enter city: ";
    	getline(cin, e.city);
    	cin.ignore();
    
    	cout << "Enter state: ";
    	getline(cin, e.state);
    	cin.ignore();
    
    	cout << "Enter zipcode: ";
    	cin >> e.zipcode;
    	cin.ignore();
    
    	cout << "Enter phone number: ";
    	cin >> e.phonenumber;
    
    	cout << "Enter salary: ";
    	cin >> e.salary;
    
    	cout << endl << endl;
    
    	return e;
    }
    
    Employee RasieSalary(Employee * a, int N)
    {
    	int i;
    	for(i = 0; i < N ; i++)
    	{
    		a[i] = (.06 * a[i]) + a[i];
    	}
    	return Employee;
    }
    
    void DisplayArrayOfEmployees(Employee * a, int N)
    {
    	int i;
    	
    	for ( i = 0; i < N; i++)
    	{
    		a[i] = DisplayEmployee();
    }
    
    void DisplayEmployee(Employee e)
    {
    
    	cout << e.ID << "\t" << e.lastname << "\t" << e.salary << endl;
    
    }

    employee.h
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    typedef struct     {
    			int ID;
    			string firstname;
    			string lastname;
    			string address;
    			string city;
    			string state;
    			string zipcode;
    			string phonenumber;
    			double salary;
    		   }			Employee;
    
    // Where Function Prototypes For Cpp Files Go.
    
    Employee CollectData(); // Returns Employee
    
    void DisplayEmployee( Employee e ); // Give Employee a variable name. Returns Nothing/Void
    
    double FindHighestSalary( Employee * a, int N ); // To find a higest salary we must use an Array. (So We Can Loop Through It)
    
    void ReadEmployees( Employee * a, int N ); // Reads an Array of Employees Returns Nothing.
    
    void DisplayArrayOfEmployees(Employee(Employee * a, int N)); // displays the array of employees by calling DisplayEmployee function
    
    Employee RaiseSalary(Employee * a, int N); // 6&#37; raise returns Employee
    
    double FindLowestSalary( Employee * a, int N); // lowest number in arrray reutnrs lowest
    main.cpp
    Code:
    #include <iostream>
    #include <string>
    
    #include "employee.h"
    
    using namespace std;
    
    int main()
    {
    	int N;
    	Employee * a ;
    	int again;
    
    	for( ; ; )
    {
    
    	cout << "How many this time: ";
    	cin >> N;
    	a = new Employee[N];
    
    	ReadEmployees(a, N);
    	DisplayArrayOfEmployees(a ,N);
    	FindLowestSalary(a, N);
    	RaiseSalary(a, N);
    	DisplayArrayOfEmployees(a, N);
    
    	cout << "Enter 0 to end, non-zero to repeat; ";
    	cin >> again;
    	if( !again ) break;
    
    }
    	free(Employee);	
    	
    	return 0;
    }
    Last edited by greatonesv; 11-19-2008 at 03:09 PM. Reason: finished code

Popular pages Recent additions subscribe to a feed