Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i am stuck at this,
C++
#include "stdafx.h"

#define myemployee 200
typedef struct

{
	int id_number; int phone_number;  int  age; char gender; double annual_salary;
}

employee;


int main()
{
	
	
		printf("employee's id number - ");
		scanf_s("%d", &myemployee[0].id_number);
		
    return 0;
}



Problem Statement (s):

The information of every employee working inside a company is stored in a file named “employee.dat”.
Each record (line) inside the file contains:
• Employee’s id number (integer)
• Employee’s phone number (integer)
• Employee’s age (integer)
• Employee’s gender (char)
• Employee’s annual salary (double)
• TRY Employee s name (string)

Define an array to store the data corresponding to the employees
(number of elements=200).

In the main program, open/read employee.dat and store the employees’ info in the array. Write the necessary C code inside your main program to:

1.Find the total number of employees.
2.Find the number of employees aged over 50.
3.Find the total number of males and females.
4.Find the total annual salary that company is paying to its employees.
5.Create a file named Phone.dat containing only employees’ surnames and phone numbers.

An example of the emplyees.dat file is as follows:

100 49217775 25 m 50000
110 40217865 32 m 47500
1 09 23425432 54 f 67000
115 67568908 43 m 54327
230 90876543 62 f 89000
120 34236785 41 f 58000
130 21346579 32 m 36000

Can you think on a way to implement an employee structure and use it in the program?
Posted
Updated 13-Jan-16 23:16pm
v7
Comments
_Asif_ 14-Jan-16 3:19am    
This is homework right?
Leo Chapiro 14-Jan-16 3:24am    
What have you tried to fulfill your homework, dude? How can we help you?
Member 12202551 14-Jan-16 4:19am    
if u can help dont post useless comments ..... see sol posted by Jochen Arndt
does that do my homework ??????
have u even understand problem or just comments on eles ???????
Sergey Alexandrovich Kryukov 14-Jan-16 11:27am    
Calm down. This is simply rude. You have the same rights as other members, and all members have to right of free speech. Why would like to help you if you show hysterical reaction on every comment you don't like?
—SA

You have:
C++
#define myemployee 200
// ...
scanf_s("%d", &myemployee[0].id_number);

What do you expect to happen?

The define statement is processed by the preprocessor replacing the occurrences of myemployee with 200. The result is than passed to the compiler. The resulting line seen by the compiler is then:
C++
scanf_s("%d", &200[0].id_number);

That is obviously an invalid C/C++ statement and generates a compiler error.

What you probably want to do is defining a max. number of employees and an array to store the information:
C++
// Max. number of supported employees.
#define MAX_EMPLOYEES 200

int main()
{
    // Storage for employee information
    employee myemployees[MAX_EMPLOYEES];

    printf("employee's id number - ");
    scanf_s("%d", &myemployees[0].id_number, sizeof(employee.id_number));
    		
    return 0;
}

Note that I have used all upper case for the defined constant because that is common practice and added the missing size parameter for scanf_s.
 
Share this answer
 
v2
Comments
Member 12202551 14-Jan-16 4:15am    
thanks
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Comments
Patrice T 14-Jan-16 3:45am    
+5
Member 12202551 14-Jan-16 4:15am    
have i said that give me code or do my homework ????
Patrice T 14-Jan-16 4:26am    
No need to tell, it is obviously some kind of homework.
If you want help on your sample code, state what is the problem; error message ans position.
Member 12202551 14-Jan-16 4:39am    
see the other soloution posted by Jochen Arndt !!!!!!
have i asked him different question ??????????
he gave me ans for what is wrong in my code
he dosent post any useless comment
Member 12202551 14-Jan-16 4:16am    
i posted that all because i want to let u know what is the problem !!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900