C ghostwriting structure array homework ghostwriting ghostwriting

C ghost writing structure array homework ghost writing and doing
comprehensive training-structure and structure array

1. Experiment hours 4 hours
2. Experiment purpose
1. Master the definition and initialization of structure type variables and structure arrays;
2. 2. Master the input and output of structure array
; Master the application of arrays of structures in related algorithms.
3. Experimental content
1. When solving practical problems, it is rare to use a single structure type variable alone, usually in the form of a structure type array. A structure array is a set of variables with the same structure type.
For example: if the name, gender, student number and three-subject test scores of 20 students in a class are defined, they can be defined as a structure array. As follows:
struct /*define student struct type*/
{
char name[20]; /*student name* /
char sex; /*gender* /
long num; /*student number* /
float score[3]; /*Three subjects test scores*/
} stud[20]; /*Define the structure type array stud, the array has 20 structure type elements*/

It can also be defined as:
struct stu /*define the student struct type*/
{
char name[20]; /*student name* /
char sex; /*gender* /
long num; /*student number* /
float score[3 ]; /*Three subject test scores*/
};
struct stu stud[20]; /*Define a structure type array with 20 structure type elements*/

The access form of structure array members is: structure array element.member name
The reference form of each member of the array element is:
stud[0].name, stud[0].sex, stud[0].score[i];
stud [1].name, stud[1].sex, stud[1].score[i];
...
...
stud[19].name, stud[19].sex, stud[19].score[ i];

2. The following program stores the data of 5 workers in the structure array worker, including serial number, name, age, salary, and pay attention to the input and output methods of the data.
struct work /*Basic information of employees*/
{ char num[10]; /*Work number*/
char name[10]; /*Name*/
int age; /*Age*/
int salary; /*Wage*/
} worker[5];
main( )
{ int i;
for(i=0;i<5;i++)
{ scanf("%s%s",worker[i].num,worker[i].name); / *Enter job number and name*/
scanf("%d%d",&worker[i].age,&worker[i].salary);} /*Enter age and salary*/
for(i=0;i<5 ;i++)
{ printf("%s\t%s\t%d\t%d\n",worker[i].num,worker[i].name,worker[i].age,worker[i] .salary); }
}

3. The following program stores the numbers and names of 5 workers in the structure array worker, uses the gets and puts functions, and pays attention to the input and output methods of the data:
#include “stdio.h”
struct work
{ char num[10];
char name[10];
} ;
main()
{ int i;
struct work worker[5];
for(i=0;i<5;i++)
{ gets(worker[i].num ); /*Enter worker number* /
gets(worker[i].name); /*input name*/
}
for(i=0;i<5;i++)
{ puts(worker[i].num );printf(" "); /*output Worker number*/
puts(worker[i].name);printf("\n"); /*output name*/
}
}


4. If there is a structure array that can contain the information of 20 students, the members of the structure include student number, name, language, mathematics, English and average score, the programming implements the input and output of the structure array for these 20 students and the calculation The average score of each student is calculated, and the reference procedure is as follows.
#include <stdio.h>
struct student /*Define student structure type*/
{
int no; /*student number* /
char name[20]; /*student name* /
int chinese; /*Chinese grade*/
int maths; /*Math grade*/
int english; /*English grade*/
float ave; /*Average grade*/
}stu[20]; /*Define a structure type array with 20 structure type elements*/

main( )
{ int i,length=0,n;
printf("Input the number of student:");
scanf("%d",&n); /*Enter the actual number of students*/
for(i=length;i <length+n;i++)
{
printf("the %d student's no: ",i+1);
scanf("%d",&stu[i].no); /*Enter student number* /
printf("the %d stdent's name: ",i+1);
scanf("%s",stu[i].name); /*Enter student name* /
printf("the %d stdent's chinese: ",i+1);
scanf("%d",&stu[i].chinese); /*Enter Chinese grades*/
printf("the %d stdent's maths: ",i+1);
scanf("%d",&stu[i]. maths); /*Enter math grades*/
printf("the %d stdent's english: ",i+1);
scanf("%d",&stu[i].english); /*Enter English grades*/

stu[i].ave=(stu[i].chinese+stu[i].maths+stu[i].english)/3.0;
/*Calculate the average grade of each student*/
printf("\n") ;
}
length=length+n;
printf("\tNo\tName\tChinese\tMaths\tEnglish\tAveage\n\n");
for(i=0;i<length;i++)
{ printf("%8d%10s %8d%8d%8d%8.1f\n",stu[i].no,stu[i].name,
stu[i].chinese,stu[i].maths,stu[i].english,stu[ i].ave);
} /*Output student information*/
}


5. For the input and output of the information of four employees of an enterprise, the reference procedure is as follows.
main( )
{ struct employee /*Basic information of employee*/
{ int num; /*job number*/
char name[8]; /*name*/
int age; /*age*/
int salary; /*salary*/
}em[4];
int i;
for(i=0;i<4;i++)
{ scanf("%d",&em[i].num); /*Enter job number*/
scanf("%s" ,em[i].name); /*Enter name*/
scanf("%d",&em[i].age); /*Enter age*/
scanf("%d",&em[i].salary) ; /*Enter salary*/
}
for(i=0;i<4;i++)
{ printf ("%d ",em[i].num); /*Output job number*/
printf("%s ", em[i].name); /*output name*/
printf("%d ",em[i].age); /*output age*/
printf("%d ",em[i].salary); /*output salary*/
printf("\n");
}
}


6. Find the average salary of four employees in an enterprise
main( )
{ struct employee /*basic information of employees*/
{ int num; /*job number*/
char name[8]; /*name*/
int age; / *age*/
int salary; /*salary*/
}em[4]={{1,"wang",25,450},{1,"li",38,890},{3,"qi",30,234},{ 4,"jiang",54,759}};
float s=0,aver; int i;
for(i=0;i<4;i++)
s+=em[i].salary;
aver=s/4.0;
printf(" %f\n ", aver); /*output average salary*/
}


7. Find out the highest salary of the four employees of the enterprise and all his information.
main( )
{ struct employee /*Basic information of employee*/
{ int num; /*job number*/
char name[8]; /*name*/
int age; /*age*/
int salary; /*salary*/
}em[4]={{1,"wang",25,450},{1,"li",38,890},{3,"qi",30,890},{4,"jiang",54,759}};
int i ,max=em[0].salary;
for(i=0;i<4;i++)
if (em[i].salary >max) max=em[i].salary;
printf("%d\n " ,max);
for(i=0;i<4;i++)
if (em[i].salary==max)
{ printf ("%d ",em[i].num); /*output job number* /
printf("%s ",em[i].name); /*output name*/
printf("%d ",em[i].age); /*output age*/
printf("%d ", em[i].salary); /*output salary*/
printf("\n");
}
}


8. Find employees of an enterprise who are older than 35 and display all their information.
main( )
{ struct employee /*Basic information of employee*/
{ int num; /*job number*/
char name[8]; /*name*/
int age; /*age*/
int salary; /*salary*/
}em[4]={{1,"wang",25,450},{1,"li",38,890},{3,"qi",30,234},{4,"jiang",54,759}};
int i ;
for (i=0;i<4;i++)
if (em[i].age>35)
{ printf ("%d ",em[i].num); /*output job number*/
printf(" %s ",em[i].name); /*output name*/
printf("%d ",em[i].age); /*output age*/
printf("%d ",em[i] .salary); /*output salary*/
printf("\n");
}
}

9. Sort the information of employees of an enterprise in descending order of salary.
main()
{ struct employee /*Basic information of employee*/
{ int num; /*job number*/
char name[8]; /*name*/
int age; /*age*/
int salary; /*salary*/
}em[4]={{1,"wang",25,450},{2,"li",38,890},{3,"qi",30,234},{4,"jiang",54,759}};
int i ,j,x,y,t; char ch[8];
for(i=0;i<4-1;i++ )
for(j=0;j<4-1-i;j++ )
if (em[j ].salary<em[j+1].salary)
{ t=em[j].num; /*Exchange worker number*/
em[j].num=em[j+1].num;
em[j+ 1].num=t;
strcpy(ch,em[j].name); /*exchange names*/
strcpy(em[j].name,em[j+1].name);
strcpy(em[j+ 1].name,ch);
t=em[j].age; /*swap age*/
em[j].age =em[j+1].age;
em[j+1].age =t;
t=em[j].salary; /*Exchange salary*/a
em[j].salary =em[j+1].salary;
em[j+1].salary =t;
}
for(i=0;i<4;i++)
{ printf ("%d ",em[ i].num); /*output job number*/
printf("%s ",em[i].name); /*output name*/
printf("%d ",em[i].age); / *output age*/
printf("%d ",em[i].salary); /*output salary*/
printf("\n");
}
}


Fourth, the experimental matters needing attention
1. Each member of the structure is allocated an independent storage unit, respectively.
2. The scanf( ) function cannot be used to assign the entire structure to the structure, and the value of the structure variable can only be changed by assigning members to the structure.
http://www.6daixie.com/contents/13/1362.html

 

The core members of the team mainly include Silicon Valley engineers, BAT front-line engineers, top 5 master and doctoral students in China, and are proficient in German and English! Our main business scope is to do programming assignments, course design and so on.

 

Our field of direction: window programming, numerical algorithm, AI, artificial intelligence, financial statistics, econometric analysis, big data, network programming, WEB programming, communication programming, game programming, multimedia linux, plug-in programming program, API, image processing, embedded/MCU database programming, console process and thread, network security, assembly language hardware Programming software design engineering standards and regulations. The ghostwriting and ghostwriting programming languages ​​or tools include but are not limited to the following:

C/C++/C# ghostwriting

Java ghostwriting

IT ghostwriting

Python ghostwriting

Tutored programming assignments

Matlab ghostwriting

Haskell ghostwriting

Processing ghostwriting

Building a Linux environment

Rust ghostwriting

Data Structure Assginment

MIPS ghostwriting

Machine Learning homework ghostwriting

Oracle/SQL/PostgreSQL/Pig database ghostwriting/doing/coaching

web development, website development, website work

ASP.NET website development

Finance Insurance Statistics Statistics, Regression, Iteration

Prolog ghostwriting

Computer Computational method

 

Because professional, so trustworthy. If necessary, please add QQ: 99515681 or email: [email protected]

WeChat: codinghelp

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325357509&siteId=291194637
Recommended