| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Plz i want help so fasttttt
hi alll
i have to present my project tomorrow pla i cant dothis project completely can any one give me simple ideas am in trouble the program: you are required to design a c++ program for a company management by using c++,structures ,and arrays. you should record the following data in two arrays 1- employee id ,employee name,working days,daily wage 2-department id,department name the program should contain 1-add department reads from user department data and store ir 2-add employee read employee data from user and department id he working n it and store it 3 -salary calculation read dep id calculate net salary for all emp in this depart salary =(working days*daily wage)-10%tax >>>>>>>>>>>>>>>>>>>>>>>>>> my first attempt #include<iostream.h> #include<string> using namespace std; struct emp{ int emp_id; string emp_name; int w_D; int daily_wage; int dept_id; }; struct dept{ int dept_id; string dep_name; }; void add () { int id; cin>>id; for(int i =0;i<=100;i++) cin>>dept[i].dept_id; if(dept[i].dept_id==id) { cout<<"this ID exists...please enter a valid one "; i--; continue;} else cin>>dept[i].dept_id;} for(int i=0;i<=100;i++) cout<<dept[i].dept_id<<endl; thxxxxxxx allllllllllllllllllllllll plz help me |
|
#2
|
|||
|
|||
|
This is a huge task to do all in one program but.. i did it for you...
only took me 2 hours though.. Code:
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
bool reading = true;
vector <string> R;
void StringExplode(string str, string separator, vector<string>* results);
void add_user(string emp_name, int w_D, int daily_wage, int dept_id, int dept_id2, string dep_name);
string line;
int i;
struct emp{
int emp_id;
string emp_name;
int w_D;
int daily_wage;
int dept_id;
};
struct dept{
int dept_id;
string dep_name;
};
emp employee[1000000];
dept department[1000000];
int employees;
string input;
int main(){
getline(cin, input);
R.clear();
StringExplode(input, " ", &R);
if(R[0] == "add" || R[0] == "ADD"){
add_user(R[1], atoi(R[2].c_str()), atoi(R[3].c_str()), atoi(R[4].c_str()), atoi(R[5].c_str()), R[6]);
cout << "Added employee " << R[1] << endl;
}
if(R[0] == "view" || R[0] == "VIEW"){
i = 0;
fstream saved_r("saved_employees.dat", ios::in | ios::binary);
cout << "Loading employee list" << endl;
while(reading == true && saved_r.eof() == false){
R.clear();
getline(saved_r, line);
StringExplode(line, " ", &R);
if(line.length() > 0){
employee[i].emp_id = atoi(R[0].c_str());
employee[i].emp_name = R[1];
employee[i].w_D = atoi(R[2].c_str());
employee[i].daily_wage = atoi(R[3].c_str());
employee[i].dept_id = atoi(R[4].c_str());
department[i].dept_id = atoi(R[5].c_str());
department[i].dep_name = R[6];
cout << "Employee id: ";
cout << employee[i].emp_id << endl;
cout << "Employee name: ";
cout << employee[i].emp_name << endl;
cout << "Employee workdays: ";
cout << employee[i].w_D << endl;
cout << "Employee daily wage: ";
cout << employee[i].daily_wage << endl;
cout << "Employee department id: ";
cout << employee[i].dept_id << endl;
cout << "Employee department id2: ";
cout << department[i].dept_id << endl;
cout << "Employee department name: ";
cout << department[i].dep_name << endl;
cout << "-10% tax: " << (employee[i].w_D * employee[i].daily_wage) - ((employee[i].w_D * employee[i].daily_wage) * 10) / 100;
cout << endl;
}
if(line.length() <= 0){
reading = false;
}
line.clear();
R.clear();
i++;
}
saved_r.close();
employees = i;
cout << employees << " Employees" << endl;
cout << "OK \n";
}
system("PAUSE");
return 0;
}
void StringExplode(string str, string separator, vector<string>* results){
int found;
found = str.find_first_of(separator);
while(found != string::npos){
if(found > 0){
results->push_back(str.substr(0,found));
}
str = str.substr(found+1);
found = str.find_first_of(separator);
}
if(str.length() > 0){
results->push_back(str);
}
if(str == ""){
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
results->push_back("Nothing here");
}
if(!found > 0){
results->clear();
}
}
void add_user(string emp_name, int w_D, int daily_wage, int dept_id, int dept_id2, string dept_name){
i = 0;
fstream saved_w("saved_employees.dat", ios::out | ios::app);
employees++;
employee[employees].emp_id = employees;
employee[employees].emp_name = emp_name;
employee[employees].w_D = w_D;
employee[employees].daily_wage = daily_wage;
employee[employees].dept_id = dept_id;
department[employees].dept_id = dept_id2;
department[employees].dep_name = dept_name;
saved_w << employee[employees].emp_id;
saved_w << " ";
saved_w << employee[employees].emp_name;
saved_w << " ";
saved_w << employee[employees].w_D;
saved_w << " ";
saved_w << employee[employees].daily_wage;
saved_w << " ";
saved_w << employee[employees].dept_id;
saved_w << " ";
saved_w << department[employees].dept_id;
saved_w << " ";
saved_w << department[employees].dep_name;
saved_w << "\n";
saved_w.close();
}
:rockon:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Plz i want help so fasttttt |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|