
帮忙用C编个程序,急,采用加50财富值
展开全部
///////main.c///////
#include <stdio.h>
#include "StudentManage.h"
int main(int argc, const char * argv[])
{
setPercent(0.2,0.2,0.6);
getStudent();
getStudent();
getStudent();
calculateScore();
printDataAnalzy();
SortByScore();
findStudentByID();
dealloc();
return 0;
}
////StudentManage.h///////
#ifndef StudentManager_StudentManage_h
#define StudentManager_StudentManage_h
typedef struct
{
int ID;
char name[20];
int cmpScore;
int customScore;
int writeScore;
float finalScore;
} Student;
void setPercent(float cmpP,float customP,float writeP);
void setFinalScore(Student* stu);
void getStudent();
void calculateScore();
void findStudentByID();
void printDataAnalzy();
void SortByScore();
void dealloc();
#endif
////StudentManage.c///////
#include <stdio.h>
#include "StudentManage.h"
#include <stdlib.h>
float cmpPercent = 0;//上机成绩
float customPercent = 0;//平时成绩
float writePercent = 0;//期末成绩
Student * m_stus;//学生数组
int m_length;//学生个数
float min;//最低分
float max;//最高分
float avg; //平均值
int level[6];//等级分布
float passPercent;//通过率
long alAllocSize = 0;
Student temp;
void setPercent(float cmpP,float customP,float writeP)
{
cmpPercent = cmpP;
customPercent = customP;
writePercent = writeP;
}
void setFinalScore(Student *stu)
{
stu->finalScore = stu->cmpScore * cmpPercent + stu->customScore * customPercent + stu->writeScore * writePercent;
}
Student* mp;
void getStudent()
{
Student stu;
static int begin = 0;
if (begin == 0) {
long size = sizeof(stu) * 10;
m_stus = (Student*)malloc(size);
mp = m_stus;
}
else
{
if (alAllocSize > 10*sizeof(stu)) {
m_stus = realloc(m_stus,alAllocSize+10*sizeof(stu));
}
}
alAllocSize += sizeof(stu);
begin = 1;
printf("请输入学号:");
scanf("%d",&stu.ID);
printf("请输入姓名:");
scanf("%s",stu.name);
printf("请输入上机成绩:");
scanf("%d",&stu.cmpScore);
printf("请输入平时成绩:");
scanf("%d",&stu.customScore);
printf("请输入期末成绩:");
scanf("%d",&stu.writeScore);
printf("\n\n");
stu.finalScore = (float)stu.cmpScore * cmpPercent + (float)stu.customScore * customPercent + (float)stu.writeScore * writePercent;
*mp = stu;
mp++;
m_length++;
}
void dealloc()
{
free(m_stus);
m_stus = 0;
}
void calculateScore()
{
max = 0;
min = 101;
int sum = 0;
int passSum = 0;
int i;
for(i = 0; i < m_length;i++)
{
Student stu = m_stus[i];
if(stu.finalScore > max)
{
max = stu.finalScore;
}
if(stu.finalScore < min)
{
min = stu.finalScore;
}
sum += stu.finalScore;
if(stu.finalScore >=90 && stu.finalScore <= 100)
{
level[0]++;
passSum++;
}
else if(stu.finalScore >=80 && stu.finalScore <= 89)
{
level[1]++;
passSum++;
}
else if(stu.finalScore >=70 && stu.finalScore <= 79)
{
level[2]++;
passSum++;
}
else if(stu.finalScore >=60 && stu.finalScore <= 69)
{
level[3]++;
passSum++;
}
else if(stu.finalScore >=50 && stu.finalScore <= 59)
{
level[4]++;
}
else if(stu.finalScore < 50)
{
level[5]++;
}
}
avg = (float)sum/(float)m_length;
passPercent = (float)passSum/(float)m_length;
printf("最高分:%f\n最低分:%f\n平均分:%f\n及格率:%5.2f%%\n\n\n",min,max,avg,passPercent*100);
}
const Student stuZero = {-1,"",0,0,0,0};
Student getStudentWithID(int ID)
{
int i = 0;
for (i = 0; i < m_length; i++) {
Student stu = m_stus[i];
if (stu.ID == ID) {
return stu;
}
}
return stuZero;
}
void printStudent(Student stu){
printf("学号:%d\n姓名:%s\n上机成绩:%d\n平时成绩%d\n期末成绩:%d\n综合成绩:%f ",stu.ID,stu.name,stu.cmpScore,stu.customScore,stu.writeScore,stu.finalScore);
}
void findStudentByID()
{
int ID;
printf("请输入要查询的学号:");
scanf("%d",&ID);
Student stu = getStudentWithID(ID);
if(stu.ID == -1)
{
printf("学生不存在");
}
else
{
printStudent(stu);
}
}
void printStudens(Student* stus)
{
for (int i = 0; i < m_length; i++) {
Student stu = stus[i];
printStudent(stu);
printf("\n\n");
}
}
void SortByScore()
{
printf("---按成绩由高到低排名----\n");
Student* sort_Stus = (Student*)malloc(sizeof(temp)*m_length);
for (int i = 0; i < m_length; i++) {
sort_Stus[i] = m_stus[i];
}
Student* p = sort_Stus;
Student* q;
int i,j;
for (i = 0; i < m_length; i++) {
q = p+1;
for (j = i+1; j < m_length; j++) {
if (p->ID < q->ID) {
Student stu;
stu = *p;
*p = *q;
*q = stu;
}
q++;
}
p++;
}
printStudens(sort_Stus);
printf("----------\n");
}
void printDataAnalzy()
{
int i;
for(i = 0;i < 6;i++)
{
int b = 100 - i*10;
int a = b - 10;
if(i != 0)
{
b--;
}
if(i != 5)
{
printf("%d~%d\t%d人\t%5.2f%%\n",a,b,level[i],((float)level[i]/(float)m_length)*100);
}
else
{
printf("49分以下\t%d人\t%5.2f%%\n",level[i],((float)level[i]/(float)m_length)*100);
}
}
printf("\n\n");
}
#include <stdio.h>
#include "StudentManage.h"
int main(int argc, const char * argv[])
{
setPercent(0.2,0.2,0.6);
getStudent();
getStudent();
getStudent();
calculateScore();
printDataAnalzy();
SortByScore();
findStudentByID();
dealloc();
return 0;
}
////StudentManage.h///////
#ifndef StudentManager_StudentManage_h
#define StudentManager_StudentManage_h
typedef struct
{
int ID;
char name[20];
int cmpScore;
int customScore;
int writeScore;
float finalScore;
} Student;
void setPercent(float cmpP,float customP,float writeP);
void setFinalScore(Student* stu);
void getStudent();
void calculateScore();
void findStudentByID();
void printDataAnalzy();
void SortByScore();
void dealloc();
#endif
////StudentManage.c///////
#include <stdio.h>
#include "StudentManage.h"
#include <stdlib.h>
float cmpPercent = 0;//上机成绩
float customPercent = 0;//平时成绩
float writePercent = 0;//期末成绩
Student * m_stus;//学生数组
int m_length;//学生个数
float min;//最低分
float max;//最高分
float avg; //平均值
int level[6];//等级分布
float passPercent;//通过率
long alAllocSize = 0;
Student temp;
void setPercent(float cmpP,float customP,float writeP)
{
cmpPercent = cmpP;
customPercent = customP;
writePercent = writeP;
}
void setFinalScore(Student *stu)
{
stu->finalScore = stu->cmpScore * cmpPercent + stu->customScore * customPercent + stu->writeScore * writePercent;
}
Student* mp;
void getStudent()
{
Student stu;
static int begin = 0;
if (begin == 0) {
long size = sizeof(stu) * 10;
m_stus = (Student*)malloc(size);
mp = m_stus;
}
else
{
if (alAllocSize > 10*sizeof(stu)) {
m_stus = realloc(m_stus,alAllocSize+10*sizeof(stu));
}
}
alAllocSize += sizeof(stu);
begin = 1;
printf("请输入学号:");
scanf("%d",&stu.ID);
printf("请输入姓名:");
scanf("%s",stu.name);
printf("请输入上机成绩:");
scanf("%d",&stu.cmpScore);
printf("请输入平时成绩:");
scanf("%d",&stu.customScore);
printf("请输入期末成绩:");
scanf("%d",&stu.writeScore);
printf("\n\n");
stu.finalScore = (float)stu.cmpScore * cmpPercent + (float)stu.customScore * customPercent + (float)stu.writeScore * writePercent;
*mp = stu;
mp++;
m_length++;
}
void dealloc()
{
free(m_stus);
m_stus = 0;
}
void calculateScore()
{
max = 0;
min = 101;
int sum = 0;
int passSum = 0;
int i;
for(i = 0; i < m_length;i++)
{
Student stu = m_stus[i];
if(stu.finalScore > max)
{
max = stu.finalScore;
}
if(stu.finalScore < min)
{
min = stu.finalScore;
}
sum += stu.finalScore;
if(stu.finalScore >=90 && stu.finalScore <= 100)
{
level[0]++;
passSum++;
}
else if(stu.finalScore >=80 && stu.finalScore <= 89)
{
level[1]++;
passSum++;
}
else if(stu.finalScore >=70 && stu.finalScore <= 79)
{
level[2]++;
passSum++;
}
else if(stu.finalScore >=60 && stu.finalScore <= 69)
{
level[3]++;
passSum++;
}
else if(stu.finalScore >=50 && stu.finalScore <= 59)
{
level[4]++;
}
else if(stu.finalScore < 50)
{
level[5]++;
}
}
avg = (float)sum/(float)m_length;
passPercent = (float)passSum/(float)m_length;
printf("最高分:%f\n最低分:%f\n平均分:%f\n及格率:%5.2f%%\n\n\n",min,max,avg,passPercent*100);
}
const Student stuZero = {-1,"",0,0,0,0};
Student getStudentWithID(int ID)
{
int i = 0;
for (i = 0; i < m_length; i++) {
Student stu = m_stus[i];
if (stu.ID == ID) {
return stu;
}
}
return stuZero;
}
void printStudent(Student stu){
printf("学号:%d\n姓名:%s\n上机成绩:%d\n平时成绩%d\n期末成绩:%d\n综合成绩:%f ",stu.ID,stu.name,stu.cmpScore,stu.customScore,stu.writeScore,stu.finalScore);
}
void findStudentByID()
{
int ID;
printf("请输入要查询的学号:");
scanf("%d",&ID);
Student stu = getStudentWithID(ID);
if(stu.ID == -1)
{
printf("学生不存在");
}
else
{
printStudent(stu);
}
}
void printStudens(Student* stus)
{
for (int i = 0; i < m_length; i++) {
Student stu = stus[i];
printStudent(stu);
printf("\n\n");
}
}
void SortByScore()
{
printf("---按成绩由高到低排名----\n");
Student* sort_Stus = (Student*)malloc(sizeof(temp)*m_length);
for (int i = 0; i < m_length; i++) {
sort_Stus[i] = m_stus[i];
}
Student* p = sort_Stus;
Student* q;
int i,j;
for (i = 0; i < m_length; i++) {
q = p+1;
for (j = i+1; j < m_length; j++) {
if (p->ID < q->ID) {
Student stu;
stu = *p;
*p = *q;
*q = stu;
}
q++;
}
p++;
}
printStudens(sort_Stus);
printf("----------\n");
}
void printDataAnalzy()
{
int i;
for(i = 0;i < 6;i++)
{
int b = 100 - i*10;
int a = b - 10;
if(i != 0)
{
b--;
}
if(i != 5)
{
printf("%d~%d\t%d人\t%5.2f%%\n",a,b,level[i],((float)level[i]/(float)m_length)*100);
}
else
{
printf("49分以下\t%d人\t%5.2f%%\n",level[i],((float)level[i]/(float)m_length)*100);
}
}
printf("\n\n");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询