Class Employee
Hold member variables: employee number and salary
Has an array of 4 employees and include 4 employee number and salary
Has 2 member functions():
Get employee detail, namely number and salary
Display employee detail
Create the main()C++ - Help to Create coding for this question please..?
Hi iam writing a c++ code may be if I forget writing semicolon or other stupid syntax error plz check it but there is no problem in logic ok please check it
#include%26lt;iostream.h%26gt;
#include%26lt;fstream.h%26gt;
#include%26lt;string.h%26gt;
#include%26lt;stdlib.h%26gt;
class emp
{
public:
char name[31];
char salary[17];
//function to accept the friend details
void accept()
{
cout%26lt;%26lt;';Enter the name:';%26lt;%26lt;endl;
c.ingore();
cin.getline(name,30);//getline()
if(strcmp(name,';*******';)==0)
{
exit(0);
}
cout%26lt;%26lt;';Enter the Salary';%26lt;%26lt;endl;
cin.getline(salary,16);
}
void display()
{
cout%26lt;%26lt;endl%26lt;%26lt;';The Name is :';%26lt;%26lt;name%26lt;%26lt;endl;
cout%26lt;%26lt;endl%26lt;%26lt;';The salary is:%26lt;%26lt;salary%26lt;%26lt;endl;
}
};
void main()
{
char ch[20];
emp e;
char name[20];
int f=0;
while(strcmp(ch,';*****';)!=0)
{
cout%26lt;%26lt;';1. Enter the Employee details';%26lt;%26lt;endl;
cout%26lt;%26lt;';2. Display the friend details';%26lt;%26lt;endl;
cout%26lt;%26lt;';3. Exit press * 4 times)';%26lt;%26lt;endl;
cin%26gt;%26gt;ch;
if(strcmp(ch,';1';)==0)
{
ofstream o(';emp.txt';,ios:: out|ios::app);
m.accept();
o.write((char*)%26amp;m,sizeof(m));
o.close();
}
if(strcmp(ch,';2';)==0)
{
ifstream i(';friend';,ios::in);
cout%26lt;%26lt;';Enter the name of search for';%26lt;%26lt;endl;
cin.ignore();
cin.getline(name,30);
i.read((char*)%26amp;m,sizeof(m));
while(i)
{
if strcmp(name,m.name)==0)
{
m.display();
f=1;
}
i.read((char*)%26amp;m,sizeof(m));
}
if(f==0)
{
cout%26lt;%26lt;';Name not Found in the file:';%26lt;%26lt;endl;
}
}
bye!! :)C++ - Help to Create coding for this question please..?
You have a Class Employee
This is not actual code. I'm not going to give you the answer yet I will give you a hint
Employee
{
detail (char[]) //unless you want to use String
number (char[]) //unless you want to use String
salary (double)
Employee(detail, number, salary)
{
//You know what to do in a constructor class
}
String or char[] displayDetail() {}
String or char[] or double getDetail, getNumber, getSalary{}
// I'm not sure what data you want from your get unless you want all of of your data then make a get function that does so.
void main()
{
//create an array of employees
//create a menu to access your function
}
For help on how to create an array in C++
http://www.daniweb.com/forums/thread7727鈥?/a>
Sounds insanely similar. I KNOW I've seen this somewhere but I don't remember where. I feel like I've written down some little diagrams to understand this thing myself.
I'll edit this latter with some solutions, but I have to ask, are you taking Data Structures (or some variation of it) over the summer? I know I took Advanced Data Structures one summer and my professor preferred C++ eventhough the other professors preferred Java and that fact made the text book unsellable after the summer course.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment