请有人帮我这个 [英] can anyone help me in this please

查看:57
本文介绍了请有人帮我这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在这里,

  #include     stdafx.h 

#define myemployee 200
typedef struct

{
int id_number; int phone_number; int age; char 性别; double annual_salary;
}

员工;


int main()
{


printf(< span class =code-string> 员工的身份证号码 - );
scanf_s( %d,& myemployee [ 0 ] ID_NUMBER);

return 0 ;
}







问题陈述:



公司内部每位员工的信息都存储在名为employee.dat的文件中。

文件中的每条记录(行)包含:

•员工的身份证号码(整数)

•员工的电话号码(整数)

•员工年龄(整数)

•员工性别(字符)

•员工年薪(双倍)

•TRY员工姓名(字符串)



定义一个数组来存储与员工相对应的数据

(元素数量= 200)。



在主程序中,打开/读取employee.dat并将员工的信息存储在数组中。在主程序中写下必要的C代码:



1.找出员工总数。

2.查找数量50岁以上的员工。

3.找出男性和女性的总数。

4.找出公司向员工支付的年薪总额。

5.创建一个名为Phone.dat的文件,其中仅包含员工的姓氏和电话号码。



emplyees.dat文件的示例如下:



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



你能想出一种实现员工结构并在程序中使用它的方法吗?

解决方案

< blockquote>你有:

  #define myemployee 200 
// ...
scanf_s( %d,& myemployee [ 0 ]。id_number);



您期望发生什么?



预处理器处理define语句替换出现的事件 myemployee 200 。结果传递给编译器。然后编译器看到的结果行是:

 scanf_s( %d,& 200 [ 0 ]。id_number); 



这显然是一个无效的C / C ++语句并产生编译器错误。



您可能想要做的是定义最大值。员工人数和存储信息的数组:

  //  最大。支持的员工数量。 
#define MAX_EMPLOYEES 200

int main()
{
// 员工信息存储
员工myemployees [MAX_EMPLOYEES];

printf( 员工的身份证号码 - );
scanf_s( %d,& myemployees [ 0 ]。id_number, sizeof (employee.id_number));

return 0 ;
}



请注意,我已经使用了所有大写的定义常量,因为这是常见做法,并为添加了缺少的大小参数scanf_s


我们不做你的作业:它是有原因设置的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!


i am stuck at this,

#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?

解决方案

You have:

#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:

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:

// 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.


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!


这篇关于请有人帮我这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆