Sparks613 2022-06-20 22:56 采纳率: 100%
浏览 164
已结题

开头#include<graphics.h>说 [Error] graphics.h: No such file or directory该如何改?

#include
#include
#include//操纵器
#include//文件流输入输出
#include//容器
#include//算法库
#include<graphics.h>
#include<conio.h>
using namespace std;
fstream f;
typedef struct statis
{//汇总专用结构体
double average[6]={0},MAX[6]={0},MIN[6]={999,999,999,999,999,999};//平均分最高最低分
double SucessPercent[6],FailPercent[6];//及格率不及格率
int number=0,SucessNumber[6]={0},FailNumber[6]={0};//总人数,及格人数,不及格人数
}statis;
typedef struct Student
{
string id,name;
int Class;//班级
double score[6],sum=0;//成绩 总分
int totalrank=1,classrank=1;//总排名和班排名
}Student;
bool downcmp(Student a,Student b)
{//按总分降序排序
return a.sum>b.sum;
}
bool idcmp(Student a,Student b)
{//按学号排序
return a.id<b.id;
}
void stu_Rank(vector&stu)
{//排名
sort(stu.begin(),stu.end(),downcmp);//班级排名容器也按总分排序
int totalRank=1,totalcount=1;//排名,计数器
double last=-1;
int Rank[2]={1,1},Count[2]={1,1};
double Last[2]={-1,-1};//n个就开n就好了
for(auto it=stu.begin();it!=stu.end();it++)
{//走一趟总排和班排一起出!
if(last==-1)
last=-2;//就只是第一次启动不管last而已
else if(it->sum==last)//总分相同排名数不变,计数器加
totalcount++;
else
{
totalRank+=totalcount;
last=it->sum;//前一个的数据要被更新
totalcount=1;
}
it->totalrank=totalRank;
for(int i=0;i<2;i++)
{//n个到n就好,遍历已有班级
if(it->Class==i+1)
{
if(Last[i]==-1)
Last[i]=-2;//就只是第一次启动不管last而已
else if(it->sum==Last[i]||Last[i]==-1)//总分相同排名数不变,计数器加
Count[i]++;
else
{
Rank[i]+=Count[i];
Last[i]=it->sum;//前一个的数据要被更新
Count[i]=1;
}
it->classrank=Rank[i];
}
}
}
}
void stu_Out(vectorstu,string filename,int outtype)
{//输出文件名和输出类型0:txt 1:csv表格 2:直接输出
if(outtype==0)
{//txt导出
f.open(filename+".txt",ios::out);
f<<left<<setw(18)<<"学号";
f<<left<<setw(20)<<"姓名";
for(int i=0;i<6;i++)
f<<"学科"<<left<<setw(10)<<i+1;
f<<left<<setw(10)<<"总分";
f<<left<<setw(10)<<"总排名";
f<<left<<setw(10)<<"班排名"<<endl;
for(auto it=stu.begin();it!=stu.end();it++)
{
f<<left<<setw(18)<id;
f<<left<<setw(20)<name;
for(int i=0;i<6;i++)
f<<left<<setw(14)<score[i];
f<<left<<setw(10)<sum;
f<<left<<setw(10)<totalrank;
f<<left<<setw(10)<classrank;
f<<endl;
}
f.close();
}
else if(outtype==1)
{//csv表格导出
f.open(filename+".csv",ios::out);
f<<"学号,";
f<<"姓名,";
for(int i=0;i<6;i++)
f<<"学科"<<i+1<<",";
f<<"总分,";
f<<"总排名,";
f<<"班排名,"<<endl;
for(auto it=stu.begin();it!=stu.end();it++)
{
f<id<<",";
f<name<<",";
for(int i=0;i<6;i++)
f<score[i]<<",";
f<sum<<",";
f<totalrank<<",";
f<classrank<<",";
f<<endl;
}
f.close();
}
else
{//直接输出
cout<<left<<setw(18)<<"学号";
cout<<left<<setw(20)<<"姓名";
for(int i=0;i<6;i++)
cout<<"学科"<<left<<setw(10)<<i+1;
cout<<left<<setw(10)<<"总分";
cout<<left<<setw(10)<<"总排名";
cout<<left<<setw(10)<<"班排名"<<endl;
for(auto it=stu.begin();it!=stu.end();it++)
{
cout<<left<<setw(18)<id;
cout<<left<<setw(20)<name;
for(int i=0;i<6;i++)
cout<<left<<setw(14)<score[i];
cout<<left<<setw(10)<sum;
cout<<left<<setw(10)<totalrank;
cout<<left<<setw(10)<classrank;
cout<<endl;
}
}
}
vector stu_search(vectorstu,string information)
{//搜索并列出相关内容
vectorresult;
for(auto it=stu.begin();it!=stu.end();it++)
{//符合条件的都加入结果的容器
if(it->id.find(information)!=-1)
result.push_back(*it);
else if(it->name.find(information)!=-1)
result.push_back(*it);
}
return result;//输出交给主程序,返回结果容器方便删除修改的时候也能用
//stu_Out(result,"",2);直接展示搜索结果即可
}
void stu_statistics(vectorstu,string filename,int outtype)
{//统计汇总,txt:0 csv:1 直接输出:2
statis class1,class2,total;
for(auto it=stu.begin();it!=stu.end();it++)
{
if(it->Class==1)
{
class1.number+=1;//统计各班人数别放里面就一次加6人了
for(int i=0;i<6;i++)
{//遍历6科
class1.MAX[i]=max(it->score[i],class1.MAX[i]);
class1.MIN[i]=min(it->score[i],class1.MIN[i]);
class1.average[i]+=it->score[i];//先直接加,最外面知道了人数再除
if(it->score[i]>=60)//统计及格人数
class1.SucessNumber[i]+=1;
}
}
else
{
class2.number+=1;//统计各班人数
for(int i=0;i<6;i++)
{//遍历6科
class2.MAX[i]=max(it->score[i],class2.MAX[i]);
class2.MIN[i]=min(it->score[i],class2.MIN[i]);
class2.average[i]+=it->score[i];//先直接加,最外面知道了人数再除
if(it->score[i]>=60)//统计及格人数
class2.SucessNumber[i]+=1;
}
}
}
total.number=stu.size();
for(int i=0;i<6;i++)
{
class1.FailNumber[i]=class1.number-class1.SucessNumber[i];
class2.FailNumber[i]=class2.number-class2.SucessNumber[i];
class1.average[i]=class1.average[i]/class1.number;
class2.average[i]=class2.average[i]/class2.number;
class1.SucessPercent[i]=(double)class1.SucessNumber[i]/class1.number;
class1.FailPercent[i]=(double)class1.FailNumber[i]/class1.number;
class2.SucessPercent[i]=(double)class2.SucessNumber[i]/class2.number;
class2.FailPercent[i]=(double)class2.FailNumber[i]/class2.number;
//这些数据适合遍历完后再计算
total.MAX[i]=max(class1.MAX[i],class2.MAX[i]);//总的只需要在这两个班之间取一个
total.MIN[i]=min(class1.MIN[i],class2.MIN[i]);
total.SucessNumber[i]=class1.SucessNumber[i]+class2.SucessNumber[i];
total.FailNumber[i]=total.number-total.SucessNumber[i];
total.SucessPercent[i]=(double)total.SucessNumber[i]/total.number;
total.FailPercent[i]=(double)total.FailNumber[i]/total.number;
total.average[i]=(class1.average[i]+class2.average[i])/2.0;
}
if(outtype==0)
{//txt导出
f.open(filename+".txt",ios::out);
f<<left<<setw(18)<<"班级";
for(int i=0;i<6;i++)
{
f<<"均分"<<left<<setw(10)<<i+1;
f<<"最高分"<<left<<setw(10)<<i+1;
f<<"最低分"<<left<<setw(10)<<i+1;
f<<"及格人数"<<left<<setw(12)<<i+1;
f<<"不及格人数"<<left<<setw(15)<<i+1;
f<<"及格率"<<left<<setw(10)<<i+1;
f<<"不及格率"<<left<<setw(12)<<i+1;
}
f<<endl;
f<<left<<setw(18)<<"班级1";
for(int i=0;i<6;i++)
{//班级1
f<<left<<setw(10)<<class1.average[i];
f<<left<<setw(10)<<class1.MAX[i];
f<<left<<setw(10)<<class1.MIN[i];
f<<left<<setw(12)<<class1.SucessNumber[i];
f<<left<<setw(15)<<class1.FailNumber[i];
f<<left<<setw(10)<<class1.SucessPercent[i];
f<<left<<setw(12)<<class1.FailPercent[i];
}
f<<endl;
f<<left<<setw(18)<<"班级2";
for(int i=0;i<6;i++)
{//班级2
f<<left<<setw(10)<<class2.average[i];
f<<left<<setw(10)<<class2.MAX[i];
f<<left<<setw(10)<<class2.MIN[i];
f<<left<<setw(12)<<class2.SucessNumber[i];
f<<left<<setw(15)<<class2.FailNumber[i];
f<<left<<setw(10)<<class2.SucessPercent[i];
f<<left<<setw(12)<<class2.FailPercent[i];
}
f<<endl;
f<<left<<setw(18)<<"总情况";
for(int i=0;i<6;i++)
{//总
f<<left<<setw(10)<<total.average[i];
f<<left<<setw(10)<<total.MAX[i];
f<<left<<setw(10)<<total.MIN[i];
f<<left<<setw(12)<<total.SucessNumber[i];
f<<left<<setw(15)<<total.FailNumber[i];
f<<left<<setw(10)<<total.SucessPercent[i];
f<<left<<setw(12)<<total.FailPercent[i];
}
f.close();
}
else if(outtype==1)
{//csv表格导出
f.open(filename+".csv",ios::out);
f<<"班级,";
for(int i=0;i<6;i++)
{
f<<"均分"<<i+1<<",";
f<<"最高分"<<i+1<<",";
f<<"最低分"<<i+1<<",";
f<<"及格人数"<<i+1<<",";
f<<"不及格人数"<<i+1<<",";
f<<"及格率"<<i+1<<",";
f<<"不及格率"<<i+1<<",";
}
f<<endl;
f<<"班级1,";
for(int i=0;i<6;i++)
{//班级1
f<<class1.average[i]<<",";
f<<class1.MAX[i]<<",";
f<<class1.MIN[i]<<",";
f<<class1.SucessNumber[i]<<",";
f<<class1.FailNumber[i]<<",";
f<<class1.SucessPercent[i]<<",";
f<<class1.FailPercent[i]<<",";
}
f<<endl;
f<<"班级2,";
for(int i=0;i<6;i++)
{//班级2
f<<class2.average[i]<<",";
f<<class2.MAX[i]<<",";
f<<class2.MIN[i]<<",";
f<<class2.SucessNumber[i]<<",";
f<<class2.FailNumber[i]<<",";
f<<class2.SucessPercent[i]<<",";
f<<class2.FailPercent[i]<<",";
}
f<<endl;
f<<"总情况,";
for(int i=0;i<6;i++)
{//总
f<<total.average[i]<<",";
f<<total.MAX[i]<<",";
f<<total.MIN[i]<<",";
f<<total.SucessNumber[i]<<",";
f<<total.FailNumber[i]<<",";
f<<total.SucessPercent[i]<<",";
f<<total.FailPercent[i]<<",";
}
f.close();
}
else
{//直接输出
cout<<left<<setw(18)<<"班级";
for(int i=0;i<6;i++)
{
cout<<"均分"<<left<<setw(10)<<i+1;
cout<<"最高分"<<left<<setw(10)<<i+1;
cout<<"最低分"<<left<<setw(10)<<i+1;
cout<<"及格人数"<<left<<setw(12)<<i+1;
cout<<"不及格人数"<<left<<setw(15)<<i+1;
cout<<"及格率"<<left<<setw(10)<<i+1;
cout<<"不及格率"<<left<<setw(12)<<i+1;
}
cout<<endl;
cout<<left<<setw(18)<<"班级1";
for(int i=0;i<6;i++)
{//班级1
cout<<left<<setw(10)<<class1.average[i];
cout<<left<<setw(10)<<class1.MAX[i];
cout<<left<<setw(10)<<class1.MIN[i];
cout<<left<<setw(12)<<class1.SucessNumber[i];
cout<<left<<setw(15)<<class1.FailNumber[i];
cout<<left<<setw(10)<<class1.SucessPercent[i];
cout<<left<<setw(12)<<class1.FailPercent[i];
}
cout<<endl;
cout<<left<<setw(18)<<"班级2";
for(int i=0;i<6;i++)
{//班级2
cout<<left<<setw(10)<<class2.average[i];
cout<<left<<setw(10)<<class2.MAX[i];
cout<<left<<setw(10)<<class2.MIN[i];
cout<<left<<setw(12)<<class2.SucessNumber[i];
cout<<left<<setw(15)<<class2.FailNumber[i];
cout<<left<<setw(10)<<class2.SucessPercent[i];
cout<<left<<setw(12)<<class2.FailPercent[i];
}
cout<<endl;
cout<<left<<setw(18)<<"总情况";
for(int i=0;i<6;i++)
{//总
cout<<left<<setw(10)<<total.average[i];
cout<<left<<setw(10)<<total.MAX[i];
cout<<left<<setw(10)<<total.MIN[i];
cout<<left<<setw(12)<<total.SucessNumber[i];
cout<<left<<setw(15)<<total.FailNumber[i];
cout<<left<<setw(10)<<total.SucessPercent[i];
cout<<left<<setw(12)<<total.FailPercent[i];
}
cout<<endl;
}
}
void stu_append(vector&stu)
{//增加记录
int n;
puts("请输入补录个数");
cin>>n;
for(int i=0;i<n;i++)
{
puts("请输入学号 姓名 6科成绩");
Student temp;
cin>>temp.id>>temp.name;
temp.sum=0;
for(int i=0;i<6;i++)
{
cin>>temp.score[i];
temp.sum+=temp.score[i];
}
temp.Class=temp.id[10]-'0'+1;//班级也要记得和排序导入的时候一样哦
stu.push_back(temp);
}
stu_Rank(stu);//加完重新计算名次
}
void stu_change(vector&stu,int type)
{//模糊查找加修改 0修改1删除(代码高度相似所以整合)
if(type==0)
puts("请输入要修改者的信息(支持模糊查找)");
else
puts("请输入被删除者的信息(支持模糊查找)");
string information;
cin>>information;
vector result=stu_search(stu,information);
int n=result.size();
cout<<setw(20)<<"学号";
cout<<setw(20)<<"姓名";
for(int i=0;i<6;i++)
cout<<setw(10)<<"学科"+to_string(i+1);
cout<<setw(10)<<"总分";
cout<<setw(10)<<"总排";
cout<<setw(10)<<"班排"<<endl;
for(int i=0;i<n;i++)
{//输出所有符合条件的人
cout<<setw(5)<<i+1<<setw(19)<<result[i].id<<setw(20)<<result[i].name;
for(int j=0;j<6;j++)
cout<<setw(10)<<result[i].score[j];
cout<<setw(10)<<result[i].sum<<setw(10)<<result[i].totalrank;
cout<<setw(10)<<result[i].classrank<<endl;
}
if(type==0)
puts("请输入你要修改的编号");
else
puts("请输入你要删除的编号");
int index;
cin>>index;
index--;//对应物理下标
auto it=stu.begin();
for(;it!=stu.end();it++)
{//在真正大容器中找到要修改的这个
if(it->id==result[index].id)
break;
}
if(type==0)
{
puts("请输入新学号 姓名 6科成绩");
Student temp;
cin>>temp.id>>temp.name;
for(int i=0;i<6;i++)
{
cin>>temp.score[i];
temp.sum+=temp.score[i];//总分别忘记了哦
}
temp.Class=temp.id[10]-'0'+1;//班级也要记得和排序导入的时候一样哦
*it=temp;//替换
puts("修改成功");
}
else
{
stu.erase(it);//根据迭代器删除
puts("删除成功");
}
stu_Rank(stu);//修改完重新排序
}
void stu_extraappend(vector stu1,vector &stu2)
{//补录并导出stu2
vector wait;//需要进行补录的
for(auto it=stu1.begin();it!=stu1.end();it++)
{
bool flag=false;//默认没找到
for(auto it2=stu2.begin();it2!=stu2.end();it2++)
{
if(it->id==it2->id)
{
flag=true;//找到了有一样的
break;
}
}
if(flag==false)
wait.push_back(*it);
}
if(wait.size()!=0)
{
for(auto it=wait.begin();it!=wait.end();it++)
{
cout<id<<" "<name<<endl;
it->sum=0;//总分也要记得改哦
puts("请输入6科成绩");
for(int i=0;i<6;i++)
{
cin>>it->score[i];
it->sum+=it->score[i];
}
stu2.push_back(*it);
}
puts("补录完成");
stu_Rank(stu2);
}
else
puts("无需补录");

}
void stu_analysis(vector stu1,vector stu2)
{//0 txt 1csv 2直接输出
sort(stu1.begin(),stu1.end(),idcmp);
sort(stu2.begin(),stu2.end(),idcmp);
puts("请选择导出方式txt:0 Excel表格:1 直接输出:2");
int operat;
cin>>operat;
int n=stu1.size();
if(operat==0)
{
puts("请输入导出文件名");
string output;
cin>>output;
f.open(output+".txt",ios::out);
f<<left<<setw(18)<<"学号";
f<<left<<setw(20)<<"姓名";
f<<left<<setw(10)<<"总分1";
f<<left<<setw(10)<<"总分2";
f<<left<<setw(22)<<"总排名变化情况";
f<<left<<setw(22)<<"班排名变化情况"<<endl;
for(int i=0;i<n;i++)
{
f<<left<<setw(18)<<stu1[i].id;
f<<left<<setw(20)<<stu1[i].name;
f<<left<<setw(10)<<stu1[i].sum;
f<<left<<setw(10)<<stu2[i].sum;
f<<left<<setw(22)<<stu2[i].totalrank-stu1[i].totalrank;
f<<left<<setw(22)<<stu2[i].classrank-stu1[i].classrank;
f<<endl;
}
f.close();
}
else if(operat==1)
{
puts("请输入导出文件名");
string output;
cin>>output;
f.open(output+".csv",ios::out);
f<<"学号,";
f<<"姓名,";
f<<"总分1,";
f<<"总分2,";
f<<"总排名变化情况,";
f<<"班排名变化情况,"<<endl;
for(int i=0;i<n;i++)
{
f<<stu1[i].id<<",";
f<<stu1[i].name<<",";
f<<stu1[i].sum<<",";
f<<stu2[i].sum<<",";
f<<stu2[i].totalrank-stu1[i].totalrank<<",";
f<<stu2[i].classrank-stu1[i].classrank<<",";
f<<endl;
}
f.close();
}
else
{
cout<<left<<setw(18)<<"学号";
cout<<left<<setw(20)<<"姓名";
cout<<left<<setw(10)<<"总分1";
cout<<left<<setw(10)<<"总分2";
cout<<left<<setw(22)<<"总排名变化情况";
cout<<left<<setw(22)<<"班排名变化情况"<<endl;
for(int i=0;i<n;i++)
{
cout<<left<<setw(18)<<stu1[i].id;
cout<<left<<setw(20)<<stu1[i].name;
cout<<left<<setw(10)<<stu1[i].sum;
cout<<left<<setw(10)<<stu2[i].sum;
cout<<left<<setw(22)<<stu2[i].totalrank-stu1[i].totalrank;
cout<<left<<setw(22)<<stu2[i].classrank-stu1[i].classrank;
cout<<endl;
}
}
}
void picture()
{
initgraph(640,480);
IMAGE img;
loadimage(&img,_T("菜单.jpg"));
putimage(0,0,&img);
getch();
closegraph();
}
int main(void)
{
vector stu1,stu2;
string source,output;
puts("请输入文件名1");
cin>>source;
f.open(source+".txt",ios::in);//根据文件名打开相对路径文件
Student temp;
while(f>>temp.id>>temp.name)
{//没必要while里面读完一行,先读2个 成绩放里面用循环读就好了
for(int i=0;i<6;i++)
{
f>>temp.score[i];
temp.sum+=temp.score[i];//总分
}
temp.Class=temp.id[10]-'0'+1;
stu1.push_back(temp);
temp.sum=0;//记得恢复
}
stu_Rank(stu1);
f.close();
puts("请输入文件名2");
cin>>source;
f.open(source+".txt",ios::in);//根据文件名打开相对路径文件
while(f>>temp.id>>temp.name)
{//没必要while里面读完一行,先读2个 成绩放里面用循环读就好了
for(int i=0;i<6;i++)
{
f>>temp.score[i];
temp.sum+=temp.score[i];//总分
}
temp.Class=temp.id[10]-'0'+1;
stu2.push_back(temp);
temp.sum=0;//记得恢复
}
stu_Rank(stu2);
f.close();
cout<<left<<setw(50)<<"++"<<endl;
cout<<left<<setw(51)<<"|1.导出数据(已计算排序) 2.统计汇总成绩情况"<<"|\n";
cout<<left<<setw(49)<<"|3.查询数据(模糊查找) 4.增加数据"<<"|\n";
cout<<left<<setw(48)<<"|5.删除数据(含查找) 6.修改数据(含查找)"<<"|\n";
cout<<left<<setw(41)<<"|7.数据补录 8.成绩分析"<<"|\n";
cout<<left<<setw(50)<<""<<endl;
puts("|0.图片菜单|");
puts("请输入对应操作编号");

int choose;
while(cin>>choose)
{
    if(choose==0)
        picture();
    else if(choose==1)
    {
        puts("请选择导出方式txt:0 Excel表格:1 直接输出:2");
        int operat;
        cin>>operat;
        if(operat!=2)
        {
            puts("请输入导出文件名");
            string output;
            cin>>output;
            stu_Out(stu1,output+"1",operat);
            stu_Out(stu2,output+"2",operat);
        }
        else
        {
            stu_Out(stu1,"",operat);
            stu_Out(stu2,"",operat);
        }
    }
    else if(choose==2)
    {
        puts("请选择导出方式txt:0 Excel表格:1 直接输出:2");
        int operat;
        cin>>operat;
        if(operat!=2)
        {
            puts("请输入导出文件名");
            string output;
            cin>>output;
            stu_statistics(stu1,output+"1",operat);
            stu_statistics(stu2,output+"2",operat);
        }
        else
        {
            stu_statistics(stu1,"",operat);
            stu_statistics(stu2,"",operat);
        }
    }
        
    
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 7月5日
      • 已采纳回答 6月27日
      • 创建了问题 6月20日

      悬赏问题

      • ¥15 使用Java语言编写程序
      • ¥100 AZURE创建地图类webapp
      • ¥20 51单片机实训实验报告
      • ¥15 C# 循环读写数据中途突然变慢
      • ¥15 用Java实现双端队列
      • ¥150 ID3决策树实现分类
      • ¥15 multisim10安装后,找不到NI License Manager的程序来安装许可证
      • ¥15 C++银行卡系统 Help!
      • ¥15 R语言数据分析的相关问题
      • ¥15 模型导入SP后贴图纹理只有一个,拆了四张UV的,怎么解决?