C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 25th, 2006, 03:26 PM
gunslinger16 gunslinger16 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 2 gunslinger16 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h
Reputation Power: 0
Help with arrays

This is the program I need to create:

Problem

You have been tasked by your boss to write a program to keep track of all the engineers in your firm.

Specifications

The class definition you will use is in a file located on the network - Outbox\ExampleProjects\engineer.h). You must use this class definition without altering it.
Create the class implementation file (engineer.cpp) based on the class definition in the engineer.h file.
In your main program, create an array of 20 engineer objects.
Run the program from a menu with the following selections:
View (list all information about each engineer, one engineer per line)
Add (add an engineer to the list)
Delete (delete an engineer from the list)
Edit (change an engineer's information)
Exit (exit the program)
Write menu functions corresponding to menu items 1-4. Pass the array and the array count to each function; have the function perform the appropriate operation on the array.
NOTE: 20 is the array size; count is the actual number of objects stored in the array.
The information contained in the array will be stored in a file named engineer.dat.
The first time the program runs, it should create this file.
Each time the program runs thereafter, it should load the information from the file into the array.
The program should save the array information in the file automatically before it terminates.



Attatched are my code files and header file. PLEASE help with why I can't compile and run properly!

Reply With Quote
  #2  
Old April 25th, 2006, 03:29 PM
gunslinger16 gunslinger16 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 2 gunslinger16 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h
Reputation Power: 0
Sorry, do't know if the code came through on attatchments, so here it is:

# include <iostream>
# include <fstream>
# include <string>
# include "engineer.h"

using namespace std;

// member function definitions
//default construcor
//Engineer::Engineer():fName(""),lName(""),degree(""),hireDate(""),salary(0)
//{

//}

//constructor with parameters
Engineer::Engineer( string fN, string lN, string deg, string hDate, double sal): fName(fN),lName(lN),degree(deg),hireDate(hDate),sa lary(sal)
{

}

//accessor functions
string Engineer::FName()
{
return fName;
}//end FName

string Engineer::LName()
{
return lName;
}

string Engineer:: Degree()
{
return degree;
}// end Degree

string Engineer:: HireDate()
{
return hireDate;
}// end HireDate

double Engineer:: Salary()
{
return salary;
}// end salary

// modifier functions

void Engineer::setFName(string first)
{
fName = first;
}//end setFName

void Engineer::setLName(string last)
{
lName = last;
}//end setLName

void Engineer::setDegree(string schooling)
{
degree = schooling;
}//end setDegree

void Engineer::setHireDate(string hire)
{
hireDate = hire;
}//end setHireDate

void Engineer::setSalary(double money)
{
salary = money;
}//end setSalary

//I/O Functions

void Engineer::getFName( istream &in )
{
in >> fName;
}// end getfName

void Engineer::getLName( istream &in )
{
in >> lName;
}// end getlName

void Engineer::getDegree( istream &in )
{
in >> degree;
}// end getdegree

void Engineer::getHireDate( istream &in )
{
in >> hireDate;
}// end gethireDate

void Engineer::getSalary( istream &in )
{
in >> salary;
}// end getsalary

void Engineer:utSalary( ostream &out )
{
out << salary;
}

void Engineer:utFName( ostream &out )
{
out << fName;
}

void Engineer:utLName( ostream &out )
{
out << lName;
}

void Engineer:utDegree( ostream &out )
{
out << degree;
}

void Engineer:utHireDate( ostream &out )
{
out << hireDate;
}
__________________________________________________ _


# include "engineer.h"
# include <iostream>
# include <fstream>
# include <string>
# include <cstdlib>
# include <cstring>
# include <iomanip>


using namespace std;
void View (Engineer emloyee[], int count);
void Add (Engineer emloyee[], int count);
void Delete(Engineer emloyee[], int count);
void Edit (Engineer emloyee[], int count);
int count=0;

int main()
{
// Decalring and initializing variables
Engineer employee [20];

ifstream myfile;
ofstream outfile;
myfile.open("engineer.txt");
if (myfile.fail())
{
cout<<"Error occurred while opening file \n";
}

else
{

do
{
employee[count].getFName (myfile);
employee[count].getLName (myfile);
employee[count].getDegree (myfile);
employee[count].getHireDate (myfile);
employee[count].getSalary (myfile);
count++;
}while ( !myfile.eof());
}
myfile.close();


char selection;

// Displaying the menu
do
{
system ("cls");
cout <<"Main Menu \n\n"
<<"1. View information about engineer \n"
<<"2. Add an enginner to the list \n"
<<"3. Delete an engineer from the list\n"
<<"4. Edit the list \n"
<<"5. Exit \n\n"
<<"Selection: \n";

// Getting a Users Selection
selection = cin.get();

// Process Menu Selection
switch (selection)
{
case '1':
system ("cls");
View (employee,count);
system ("pause");
break;
case '2':
system ("cls");
Add (employee,count);
system("pause");
break;
case '3':
system ("cls");
Delete(employee,count);
system("pause");
break;
case '4':
system ("cls");
Edit (employee,count);
system("pause");
break;
case '5':
break;
}
}while (selection != '5');
// Saving array info to the file
outfile.open("engineer.txt");
for(int i=0;i<count;i++)
{
employee[i].putFName(outfile);
outfile<<setw(4);
employee[i].putLName(outfile);
outfile<<setw(4);
employee[i].putDegree(outfile);
outfile<<setw(4);
employee[i].putHireDate(outfile);
outfile<<setw(4);
employee[i].putSalary(outfile);
outfile<<endl;
}
outfile.close();
return 0;
}

//--------------------------------------------------------------------------------------------------------------------------------
void View (Engineer employee[], int count)
{
cout<<"The engineers of our firm"<<endl<<endl;
for (int i=0; i<count-1; i++)
{
employee[i].putFName(cout);
cout<<" ";
employee[i].putLName(cout);
cout<<" ";
employee[i].putDegree(cout);
cout<<" ";
employee[i].putHireDate(cout);
cout<<" ";
employee[i].putSalary(cout);
cout<<endl;
}

cout<<endl;
cout<<"Number of employees: "<<count-1<<endl;
}
//-------------------------------------------------------------------------------------------------------------------------
void Add (Engineer employee[], int count)
{

//Getting Employees information from the user
cout<<"Employee First Name: "<<endl;
employee[count].getFName(cin);
cout<<"Employee Last Name: "<<endl;
employee[count].getLName(cin);
cout<<"Employee's Degree: "<<endl;
employee[count].getDegree(cin);
cout<<"Employee's Hire Date: "<<endl;
employee[count].getHireDate(cin);
cout<<"Employee's Salary: "<<endl;
employee[count].getSalary(cin);
//Increment count
count++;
//Sending the updated list to the screen
cout<<endl<<endl<<"Updated Engineer List: "<<endl<<endl;
for (int i=0; i<count; i++)
{
employee[i].putFName(cout);
cout<<" ";
employee[i].putLName(cout);
cout<<" ";
employee[i].putDegree(cout);
cout<<" ";
employee[i].putHireDate(cout);
cout<<" ";
employee[i].putSalary(cout);
cout<<endl;
}
cout<<"Number of employees: "<<count<<endl;

}
//-------------------------------------------------------------------------------------------------------------------------
void Delete(Engineer employee[], int num)
{
//Initializing Variables
string ln,l;
int index=-1;
cout<<"Enter the last name of the employee that you want to delete"<<endl;
cin>>ln;
//Finding the name that we want to delete
for(int i=0;i<num;i++)
{
l=employee[i].LName();
if (ln==l)
{
index=i;
}
}
//Deleting the name
if (index<0)
cout<<" No employee found by that name"<<endl;
else
{
for (i=index;i<num;i++)
{
employee[i]=employee[i+1];
}
count--;
}
//Sending the updated list to the screen
cout<<endl<<endl<<"Updated Engineer List: "<<endl<<endl;
for ( i=0; i<count; i++)
{
employee[i].putFName(cout);
cout<<" ";
employee[i].putLName(cout);
cout<<" ";
employee[i].putDegree(cout);
cout<<" ";
employee[i].putHireDate(cout);
cout<<" ";
employee[i].putSalary(cout);
cout<<endl;
}


cout<<"Number of employees: "<<count<<endl;


}
//-------------------------------------------------------------------------------------------------------------------------
void Edit(Engineer employee[], int num)
{
//Initializing Variables
string ln,l,F,L,D,H;
int index=-1, choice;
double S;
cout<<"Enter the last name of the employee that you want to edit"<<endl;
cin>>ln;
//Finding the name that we want to edit
for(int i=0;i<num;i++)
{
l=employee[i].LName();
if (ln==l)
{
index=i;
}
}

system ("cls");
do{
cout<<"1. First Name \n"
<<"2. Last Name \n"
<<"3. Type of Degree \n"
<<"4. Date Hired \n"
<<"5. Salary \n"
<<"6. Make no changes \n"
<<"Which data field would you like to change? \n\n";

choice = cin.get();
system ("cls");
switch (choice)
{
case '1':
system("cls");
cout<<"Replace With: "<<endl;
cin>>F;
employee[index].setFName(F);
system("pause");
break;
case '2':
system("cls");
cout<<"Replace With: "<<endl;
cin>>L;
employee[index].setLName(L);
system("pause");
break;
case '3':
system("cls");
cout<<"Replace With: "<<endl;
cin>>D;
employee[index].setDegree(D);
system("pause");
break;
case '4':
system("cls");
cout<<"Replace With: "<<endl;
cin>>H;
employee[index].setHireDate(H);
system("pause");
break;
case '5':
system("cls");
cout<<"Replace With: "<<endl;
cin>>S;
employee[index].setSalary(S);
system("pause");
break;
case '6':
cout<<"Editing complete, Print out updated list"<<endl;
break;
}
}while(choice != '6');


//Sending the updated list to the screen
cout<<endl<<endl<<"Updated List: "<<endl<<endl;
for ( i=0; i<count; i++)
{
employee[i].putFName(cout);
cout<<" ";
employee[i].putLName(cout);
cout<<" ";
employee[i].putDegree(cout);
cout<<" ";
employee[i].putHireDate(cout);
cout<<" ";
employee[i].putSalary(cout);
cout<<endl;
}


}

_________________________________________________

#ifndef ENGINEER_H
#define ENGINEER_H

//engineer class definition
#include<fstream>
#include<string>

using namespace std;

class Engineer
{
private:
string fName, lName, degree, hireDate;
double salary;

public:
//constructor
//Engineer( );
Engineer( string = "", string = "", string = "", string = "", double = 0.0 );

//accessor functions
string FName();
string LName();
string Degree();
string HireDate();
double Salary();

//modifier functions
void setFName( string );
void setLName( string );
void setDegree( string );
void setHireDate( string );
void setSalary( double );

//input functions
void getFName( istream& );
void getLName( istream& );
void getDegree( istream& );
void getHireDate( istream& );
void getSalary( istream& );

//output functions
void putFName( ostream& );
void putLName( ostream& );
void putDegree( ostream& );
void putHireDate( ostream& );
void putSalary( ostream& );
};

#endif

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help with arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT