程序设计任务

发布时间:2025-04-07 13:45

利用时间管理应用程序辅助任务排序 #生活技巧# #时间管理技巧# #任务优先级设定#

因为时间有限所以只简单的写了一下,若有不对的地方,敬请各位指正.

头文件 Stu.h

#ifndef CODEDEFINE_H

#define CODEDEFINE_H

#include<iostream>

using namespace std;

class student{

private:

char name[20];

char id[20];

char sex;

double graphics;

double english;

double math;

double computer;

double cLanguage;

double totGrade;

public:

student* next;

student();

student(char *,char *,char ,double ,double ,double ,double ,double);

student(student &s);

char const* getName() const;

char const* getId() const;

char getSex() const;

double getTotGrades() const;

double getGraphics()const;

double getMath() const;

double getEnglish() const;

double getComputer() const;

double getCLanguage() const;

void setName();

void setId();

void setSex();

void setGrades();

void changeStuInfor();

void showInfor();

};

bool operator< (const student& a,const student& b);

class mainSystem{

private:

student* head;

student* tail;

public:

int size;

mainSystem();

void keepInfor();

void menu();

void showStuInfor();

void showAllStuGradeInfor();

void changeStuInfor();

void deleteStuInfor();

void addStuInfor();

void exit1();

void searchStuInfor();

void searchStuWithId();

void searchStuWithName();

};

#endif

made.cpp

#include"Stu.h"

#include<conio.h>

#include<windows.h>

#include<iomanip>

#include<cstring>

#include<fstream>

#include<algorithm>

using namespace std;

bool operator < (const student& a,const student& b){

if (strcmp(a.getId(),b.getId()) < 0) return true;

return false;

}

bool operator == (const student& a,const student& b){

if(strcmp(a.getId(),b.getId()) == 0) return true;

return false;

}

student::student(){}

student::student(char *n,char *id1,char s,double g,double e,double m,double com,double cL){

for(int i=0;i<20;i++){

name[i] = n[i];

id[i] = id1[i];

}

sex = s;

graphics = g;

english = e;

math = m;

computer = com;

cLanguage = cL;

totGrade = g+e+m+com+cL;

next = NULL;

}

student::student(student &s){

for(int i=0;i<20;i++){

name[i] = *(s.getName()+i);

id[i] = *(s.getId()+i);

}

sex = s.getSex();

graphics = s.getGraphics();

english = s.getEnglish();

math = s.getMath();

computer = s.getComputer();

cLanguage = s.getCLanguage();

totGrade = s.getTotGrades();

}

char const* student::getName() const{

return name;

}

char const* student::getId() const{

return id;

}

char student::getSex() const{

return sex;

}

double student::getGraphics() const{

return graphics;

}

double student::getMath() const{

return math;

}

double student::getEnglish() const{

return english;

}

double student::getComputer() const{

return computer;

}

double student::getCLanguage() const{

return cLanguage;

}

double student::getTotGrades() const{

return totGrade;

}

void student::setName(){

char newName[20];

cout<<"\t\t请输入新的姓名:";

cin>>newName;

strcpy(name,newName);

}

void student::setSex(){

char newSex;

cout<<"\t\t请输入新的性别:";

cin>>newSex;

sex = newSex;

}

void student::setGrades(){

double g,m,e,c,cl,com;

cout<<"\t\t请输入新的成绩:"<<endl;

cout<<"\t\t物理:";

cin>>graphics;

cout<<"\t\t英语:";

cin>>english;

cout<<"\t\t数学:";

cin>>math;

cout<<"\t\t计导:";

cin>>computer;

cout<<"\t\tC语言:";

cin>>cLanguage;

totGrade = graphics+english+math+computer+cLanguage;

}

void student::changeStuInfor(){

cout<<"\t\t学生信息:"<<endl;

cout<<"\t\t姓名:"; cin>>name;

cout<<"\t\t学号:"; cin>>id;

cout<<"\t\t性别(男:1,女:2):"; cin>>sex;

cout<<"\t\t物理:"; cin>>graphics;

cout<<"\t\t英语:";cin>>english;

cout<<"\t\t数学:";cin>>math;

cout<<"\t\t计算机导论:";cin>>computer;

cout<<"\t\tC语言:";cin>>cLanguage;

}

void student::showInfor(){

cout<<setiosflags(ios::left)<<setw(8)<<name<<setw(8)<<id<<setw(8)<<(sex=='1'?"男":"女")<<setw(8)<<setprecision(4)

<<setw(8)<<graphics<<setw(8)<<english<<setw(8)<<math<<setw(8)<<computer<<setw(8)<<cLanguage<<setw(8)<<totGrade<<endl;

}

mainSystem::mainSystem(){

ifstream f;

f.open("user.txt");

if(!f){

cout<<"cant's open File"<<endl;

return;

}

size = 0;

head = new student();

tail = head;

student* temp= new student();

while( f.read((char *)temp,sizeof(student)) ){

tail->next = temp;

tail = tail->next;

temp = new student();

size++;

}

f.close();

}

void mainSystem::showStuInfor(){

system("cls");

student* temp = head->next;

cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)

<<"物理"<<setw(8)<<"英语:"<<setw(8)<<"数学:"<<setw(8)<<"计导:"<<setw(8)<<"C语言:"<<setw(8)<<"总分:"<<endl;

while(temp){

temp->showInfor();

temp = temp->next;

}

cout<<"\n"<<endl;

system("pause");

}

void mainSystem::showAllStuGradeInfor(){

system("cls");

double grade[1000];

double p[6] = {0};

student* temp = head;

int i=0;

while(temp != tail){

p[0] = ( p[0] > temp->next->getGraphics() ) ? p[0] : temp->next->getGraphics();

p[1] = ( p[1] > temp->next->getEnglish() ) ? p[1] : temp->next->getEnglish();

p[2] = ( p[2] > temp->next->getMath() ) ? p[2] : temp->next->getMath();

p[3] = ( p[3] > temp->next->getComputer() ) ? p[3] : temp->next->getComputer();

p[4] = ( p[4] > temp->next->getCLanguage() ) ? p[4] : temp->next->getCLanguage();

p[5] = ( p[5] > temp->next->getTotGrades() ) ? p[5] : temp->next->getTotGrades();

grade[i++] = temp->next->getTotGrades();

temp = temp->next;

}

double r;

int rank = 1;

cout<<"排名统计:"<<endl;

cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)<<"总分:"<<setw(8)<<"排名:"<<endl;

sort(grade,grade+i);

r = -1;

while(--i >= 0){

if(r == grade[i]) continue;

temp = head;

while(temp != tail){

if(temp->next->getTotGrades() == grade[i]) {

cout<<setiosflags(ios::left)<<setw(8)<<temp->next->getName()<<setw(8)<<temp->next->getId()

<<setw(8)<<temp->next->getSex()<<setprecision(4)<<setw(8)<<grade[i]<<setw(8)<<rank++<<endl;

}

temp = temp->next;

}

r = grade[i];

}

temp = head;

cout<<"\n物理最高分:"<<endl;

cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)<<"物理:"<<endl;

while(temp != tail){

if( temp->next->getGraphics() == p[0])

cout<<setiosflags(ios::left)<<setw(8)<<temp->next->getName()<<setw(8)<<temp->next->getId()

<<setw(8)<<temp->next->getSex()<<setprecision(4)<<setw(8)<<p[0]<<endl;

temp = temp->next;

}

temp = head;

cout<<"\n英语最高分:"<<endl;

cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)<<"英语:"<<endl;

while(temp != tail){

if( temp->next->getEnglish() == p[1])

cout<<setiosflags(ios::left)<<setw(8)<<temp->next->getName()<<setw(8)<<temp->next->getId()

<<setw(8)<<temp->next->getSex()<<setprecision(4)<<setw(8)<<p[1]<<endl;

temp = temp->next;

}

temp = head;

cout<<"\n数学最高分:"<<endl;

cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)<<"数学:"<<endl;

while(temp != tail){

if( temp->next->getMath() == p[2])

cout<<setiosflags(ios::left)<<setw(8)<<temp->next->getName()<<setw(8)<<temp->next->getId()

<<setw(8)<<temp->next->getSex()<<setprecision(4)<<setw(8)<<p[2]<<endl;

temp = temp->next;

}

temp = head;

cout<<"\n计导最高分:"<<endl;

cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)<<"计导:"<<endl;

while(temp != tail){

if( temp->next->getComputer() == p[3])

cout<<setiosflags(ios::left)<<setw(8)<<temp->next->getName()<<setw(8)<<temp->next->getId()

<<setw(8)<<temp->next->getSex()<<setprecision(4)<<setw(8)<<p[3]<<endl;

temp = temp->next;

}

temp = head;

cout<<"\nC语言最高分:"<<endl;

cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)<<"C语言:"<<endl;

while(temp != tail){

if( temp->next->getCLanguage() == p[4])

cout<<setiosflags(ios::left)<<setw(8)<<temp->next->getName()<<setw(8)<<temp->next->getId()

<<setw(8)<<temp->next->getSex()<<setprecision(4)<<setw(8)<<p[4]<<endl;

temp = temp->next;

}

system("pause");

}

void mainSystem::keepInfor(){

ofstream f("user.txt");

if(!f){

cout<<"\t\tFailed Open File"<<endl;

return ;

}

student* temp = head->next;

while(temp){

f.write((char *)temp,sizeof(student));

temp = temp->next;

}

}

void mainSystem::deleteStuInfor(){

char id[20];

student* temp = head;

cout<<"\t\t请输入学生的学号:\n\t\t";

cin>>id;

while(temp != tail){

if(strcmp(temp->next->getId(),id) == 0) {

cout<<"\t\t确认删除?(y/n) :";

char a;

cin>>a;

if(a == 'y'||a == 'Y'){

student* del = temp->next;

if(temp->next == tail) {

tail = temp;

temp->next = NULL;

size--;

delete del;

return;

}

temp->next = temp->next->next;

delete del;

keepInfor();

cout<<"\t\t删除成功\n";

size--;

return;

}

}

temp = temp ->next;

}

cout<<"\t\t未找到该学生信息"<<endl;

}

void mainSystem::addStuInfor(){

char name[20];

char id[20];

char sex;

double graphics,math,english,computer,CLanguage;

cout<<"\t\t学生信息:"<<endl;

cout<<"\t\t姓名:"; cin>>name;

cout<<"\t\t学号:"; cin>>id;

cout<<"\t\t性别(男:1,女:2):"; cin>>sex;

cout<<"\t\t物理:"; cin>>graphics;

cout<<"\t\t英语:";cin>>english;

cout<<"\t\t数学:";cin>>math;

cout<<"\t\t计算机导论:";cin>>computer;

cout<<"\t\tC语言:";cin>>CLanguage;

student* p = new student(name,id,sex,graphics,english,math,computer,CLanguage);

p->showInfor();

cout<<"\t\t确认保存?(y/n)";

char a;

cin>>a;

if(a == 'y'||a =='Y') {

student* temp = head;

while( temp != tail && *(temp->next) < *p){

temp = temp->next;

}

if(temp == tail) {

temp->next = p;

tail = p;

keepInfor();

cout<<"\t\t添加成功";

size++;

return;

}

p->next = temp->next;

temp->next = p;

keepInfor();

cout<<"\t\t添加成功";

size++;

}

}

void mainSystem::searchStuInfor(){

cout<<"\t1根据学生学号查找:\t2:根据学生姓名查找:"<<endl;

cout<<"\t\t输入:";

char a;

cin>>a;

switch(a){

case '1': searchStuWithId();break;

case '2': searchStuWithName();break;

default:break;

}

}

void mainSystem::searchStuWithId(){

student* temp = head;

char id[20];

bool key = false;

cout<<"\t\t请输入学生的学号:";

cin>>id;

while(temp != tail ){

if(strcmp(id,temp->next->getId()) == 0){

if(!key) cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)

<<"物理"<<setw(8)<<"英语:"<<setw(8)<<"数学:"<<setw(8)<<"计导:"<<setw(8)<<"C语言:"<<setw(8)<<"总分:"<<endl;

key = true;

temp->next->showInfor();

}

temp = temp->next;

}

if(!key) cout<<"NOT FOUND!"<<endl;

system("pause");

}

void mainSystem::searchStuWithName(){

student* temp = head;

char name[20];

bool key = false;

cout<<"\t\t请输入学生的姓名:";

cin>>name;

while(temp != tail){

if(strcmp(name,temp->next->getName()) == 0){

if(!key) cout<<setiosflags(ios::left)<<setw(8)<<"姓名:"<<setw(8)<<"学号:"<<setw(8)<<"性别:"<<setw(8)

<<"物理"<<setw(8)<<"英语:"<<setw(8)<<"数学:"<<setw(8)<<"计导:"<<setw(8)<<"C语言:"<<setw(8)<<"总分:"<<endl;

key = true;

temp->next->showInfor();

}

temp = temp->next;

}

if(!key) cout<<"NOT FOUND!"<<endl;

system("pause");

}

void mainSystem::changeStuInfor(){

student* temp = head;

char id[20];

bool key = false;

cout<<"\t\t请输入学生的学号:";

cin>>id;

while(temp != tail ){

if(strcmp(temp->next->getId(),id) == 0){

temp = temp->next;

temp->showInfor();

cout<<"\t1:修改姓名\t2:修改性别\n\t3:修改成绩\t4:全部修改"<<endl;

cout<<"\t输入:";

char choice;

cin>>choice;

switch(choice){

case '1': { temp->setName();keepInfor();return; }

case '2': { temp->setSex();keepInfor();return; }

case '3': { temp->setGrades();keepInfor();return; }

case '4': { temp->changeStuInfor();keepInfor();return; }

default: ;

}

}

temp = temp->next;

}

cout<<"\t\tNOT FOUND\n\t\t";

system("pause");

}

void mainSystem::menu(){

cout<<endl<<endl<<endl<<endl;

cout<<"\t"<<"***********学生信息管理系统**************"<<endl;

cout<<"\t"<<"* *"<<endl;

cout<<"\t"<<"* 1:查看学生信息 2:学生成绩统计 *"<<endl;

cout<<"\t"<<"* *"<<endl;

cout<<"\t"<<"* 3:查找学生信息 4:修改学生信息 *"<<endl;

cout<<"\t"<<"* *"<<endl;

cout<<"\t"<<"* 5:删除学生信息 6:增加学生信息 *"<<endl;

cout<<"\t"<<"* *"<<endl;

cout<<"\t"<<"* 0:退出程序 *"<<endl;

cout<<"\t"<<"* *"<<endl;

cout<<"\t"<<"*****************************************"<<endl;

cout<<"\n\n\n\n\n"<<endl;

cout<<"\t\t输入:";

}

void mainSystem::exit1(){

keepInfor();

exit(0);

}

main.cpp

#include"Stu.h"

int main(){

mainSystem* m = new mainSystem();

int choice;

while(1){

m->menu();

cin>>choice;

switch(choice){

case 1: m->showStuInfor();break;

case 2: m->showAllStuGradeInfor();break;

case 3: m->searchStuInfor();break;

case 4: m->changeStuInfor();break;

case 5: m->deleteStuInfor();break;

case 6: m->addStuInfor();break;

case 0: m->exit1();break;

default: ;

}

system("cls");

}

return 0;

}

// @author: LovelyTotoro

网址:程序设计任务 https://www.yuejiaxmz.com/news/view/855969

相关内容

任务清单小程序下载
python+flask计算机毕业设计个人任务管理系统APP(程序+开题+论文)
任务管理系统小程序如何运营
进程和计划任务管理
【七天实战微信小程序】任务清单
如何在Windows上使用任务计划程序自动执行批处理文件
社区服务小程序功能设计,社区服务小程序的功能有哪些?
Windows“任务计划程序”定时自动执行bat文件
如何在面对多任务时保持有序工作流程
微信小程序Demo:任务清单

随便看看