一个简单的学生管理系统

来源:互联网 发布:手机淘宝直播入口在哪 编辑:程序博客网 时间:2024/04/27 21:59

 

 

工程链接http://download.csdn.net/detail/a527606652/4874823

经VS2010编译通过

// 学生成绩管理系统.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "ManageStu.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 ManageStu MS;

 cout<<"-----------------------------------------------------"<<endl;
 cout<<"--"<<"                                                 "<<"--"<<endl;
 cout<<"--"<<"                                                 "<<"--"<<endl;
 cout<<"--"<<"            学生管理系统                         "<<"--"<<endl;
 cout<<"--"<<"             Made by wx                          "<<"--"<<endl;
 cout<<"--"<<"                                                 "<<"--"<<endl;
 cout<<"-----------------------------------------------------"<<endl;

 

 cout<<"-------------------------------------"<<endl;
 cout<<endl;
 cout<<"[1]------>添加学生信息"<<endl;
 cout<<"[2]------>查询学生信息"<<endl;
 cout<<"[3]------>修改学生信息"<<endl;
 cout<<"[4]------>删除学生信息"<<endl;
 cout<<"[5]------>退出学生系统"<<endl;
 cout<<endl;
 cout<<"-------------------------------------"<<endl;
 

 int choose=0;
 while(1)
 { 
  cout<<"请选择操作1->5"<<endl;
  do
  {
   cin>>choose;
   if(1==choose)
   {
    MS.AddStu();
    cout<<choose<<"操作完成!"<<endl;
   }
   else if(2==choose)
   {
    MS.SearchStu();
    cout<<choose<<"操作完成!"<<endl;
   }
   else if(3==choose)
   {
    MS.ChangeStu();
    cout<<choose<<"操作完成!"<<endl;
   }
   else if(4==choose)
   {
    MS.DeleteStu();
    cout<<choose<<"操作完成!"<<endl;
   }
   else if(5==choose)
   {
    cout<<"退出系统!"<<endl;
    exit(0);
   }
   else
   {
    cout<<"输入错误!请重新选择!"<<endl;
   }

  }while(choose!=1&&choose!=2&&choose!=3&&choose!=4&&choose!=5);
 }
 return 0;

 

//////////ManageStu.h

#pragma once

#include "Student.h"
#include<vector>
#include<iostream>

class ManageStu
{
public:
 ManageStu(void);
 ~ManageStu(void);
private:
 vector<Student> stu;

public:
 // 添加学生信息
 bool AddStu(void);
 // 查询学生信息
 bool SearchStu(void);
 // 修改学生信息
 bool ChangeStu(void);
 // 删除学生信息
 bool DeleteStu(void);
};

 

/////ManageStu.cpp

#include "StdAfx.h"
#include "ManageStu.h"


ManageStu::ManageStu(void)
{
}


ManageStu::~ManageStu(void)
{
}


// 添加学生信息
bool ManageStu::AddStu(void)
{
 int id;
 string name;
 int age;
 double chinese;
 double english;
 double math;
 double cpp;

 cout<<"输入学生id"<<endl;
 cin>>id;
 cout<<"输入学生名字"<<endl;
 cin>>name;
 cout<<"输入学生年龄"<<endl;
 cin>>age;
 cout<<"输入学生语文成绩"<<endl;
 cin>>chinese;
 cout<<"输入学生数学成绩"<<endl;
 cin>>math;
 cout<<"输入学生英语成绩"<<endl;
 cin>>english;
 cout<<"输入学生C++成绩"<<endl;
 cin>>cpp;

 Score score;
 score.chinese=chinese;
 score.english=english;
 score.math=math;
 score.cpp=cpp;

 Student ss(id,name,score,age);
 stu.push_back(ss);

 return true;
}


// 查询学生信息
bool ManageStu::SearchStu(void)
{
 int choose=0;
 int len=stu.size();
 int id;
 string name;

 cout<<"选择查询方式:1-->id查询; 2-->姓名查询"<<endl;
 cin>>choose;
 if(1==choose)
 {
  cout<<"输入要查询的id"<<endl;
  cin>>id;
  int i;
  for(i=0;i<len;i++)
  {
   if(stu[i].GetID()==id)
   {
    stu[i].putout();
    break;
   }
  }
  if(i==len)
  {
   cout<<"查无此人!"<<endl;
  }
 }
 else if(2==choose)
 {
  cout<<"输入要查询的名字"<<endl;
  cin>>name;
  int i;
  for(i=0;i<len;i++)
  {
   if(stu[i].GetName()==name)
   {
    stu[i].putout();
    break;
   }
  }
  if(i==len)
  {
   cout<<"查无此人!"<<endl;
  }
 }
 else
 {
  cout<<"输入错误!"<<endl;
  exit(0);
  return false;
 }
 return true;
}


// 修改学生信息
bool ManageStu::ChangeStu(void)
{
 int choose=0;
 int len=stu.size();
 int id;
 string name;

 cout<<"选择查询方式:1-->id查询; 2-->姓名查询"<<endl;
 cin>>choose;
 if(1==choose)
 {
  cout<<"输入要修改的同学的id"<<endl;
  cin>>id;
  int i;
  for(i=0;i<len;i++)
  {
   if(stu[i].GetID()==id)
   {
    int id;
    string name;
    int age;
    double chinese;
    double english;
    double math;
    double cpp;

    cout<<"输入学生id"<<endl;
    cin>>id;
    cout<<"输入学生名字"<<endl;
    cin>>name;
    cout<<"输入学生年龄"<<endl;
    cin>>age;
    cout<<"输入学生语文成绩"<<endl;
    cin>>chinese;
    cout<<"输入学生数学成绩"<<endl;
    cin>>math;
    cout<<"输入学生英语成绩"<<endl;
    cin>>english;
    cout<<"输入学生C++成绩"<<endl;
    cin>>cpp;

    Score score;
    score.chinese=chinese;
    score.english=english;
    score.math=math;
    score.cpp=cpp;

    Student ss(id,name,score,age);
    stu[i]=ss;
    break;
   }
  }
  if(i==len)
  {
   cout<<"查无此人!"<<endl;
  }
 }
 else if(2==choose)
 {
  cout<<"输入要查询的名字"<<endl;
  cin>>name;
  int i;
  for(i=0;i<len;i++)
  {
   if(stu[i].GetName()==name)
   {
    stu[i].putout();
    break;
   }
  }
  if(i==len)
  {
   cout<<"查无此人!"<<endl;
  }
 }
 else
 {
  cout<<"输入错误!"<<endl;
  exit(0);
  return false;
 }
 return true;
}


// 删除学生信息
bool ManageStu::DeleteStu(void)
{
 int choose=0;
 int len=stu.size();
 int id;
 string name;

 cout<<"选择查询方式:1-->id查询; 2-->姓名查询"<<endl;
 cin>>choose;
 if(1==choose)
 {
  cout<<"输入要删除同学的id"<<endl;
  cin>>id;
  int i;
  for(i=0;i<len;i++)
  {
   if(stu[i].GetID()==id)
   {
    if (i==0)
    {
     stu.clear();
    }
    else
    {
     for(int k=i;k<len-1;k++)
     {
      stu[i]=stu[i+1];
      stu.pop_back();
     }
     break;
    }
   }
  }
  if(i==len)
  {
   cout<<"查无此人!"<<endl;
  }
 }
 else if(2==choose)
 {
  cout<<"输入要删除同学的名字"<<endl;
  cin>>name;
  int i;
  for(i=0;i<len;i++)
  {
   if(stu[i].GetName()==name)
   {
    if (i==0)
    {
     stu.clear();
    }
    else
    {
     for(int k=i;k<len-1;k++)
     {
      stu[i]=stu[i+1];
      stu.pop_back();
     }
     break;
    }
   }
  }
  if(i==len)
  {
   cout<<"查无此人!"<<endl;
  }
 }
 else
 {
  cout<<"输入错误!"<<endl;
  exit(0);
  return false;
 }
 return true;
}

 

////Student.h

#pragma once
#include<string>
#include<iostream>
using namespace std;

struct Score
{
 double chinese;
 double english;
 double math;
 double cpp;
};

class Student
{
public:
 Student(int id,string name,Score score,int age);
 Student(void);
 ~Student(void);
private:
 int id;
 string name;
 Score score;
 int age;
public:
 // 访问id的接口
 int GetID(void);
 // 访问name的接口
 string GetName(void);
 //输出Student对象
 bool putout(void);
 // 访问age的接口
 int GetAge(void);
 // 访问score的接口
 Score GetScore(void);
};

 

//Student.cpp

#include "StdAfx.h"
#include "Student.h"

Student::Student(void)
{
}

Student::Student(int i1,string s1,Score s2,int i2)
{
 id=i1;
 name=s1;
 score=s2;
 age=i2;
}


Student::~Student(void)
{
}


// 访问id的接口
int Student::GetID(void)
{
 return id;
}


// 访问name的接口
string Student::GetName(void)
{
 return name;
}

// 访问age的接口
int Student::GetAge(void)
{
 return age;
}

//输出Student对象
bool Student::putout(void)
{
 cout<<"id: "<<id<<endl;
 cout<<"name: "<<name<<endl;
 cout<<"age: "<<age<<endl;
 cout<<"chinese: "<<score.chinese<<endl;
 cout<<"engilsh: "<<score.english<<endl;
 cout<<"math: "<<score.math<<endl;
 cout<<"cpp: "<<score.cpp<<endl;
 
 return true;
}

 

// 访问score的接口
Score Student::GetScore(void)
{
 return score;
}

 

// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//

#pragma once

//#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

 

// TODO: 在此处引用程序需要的其他头文件

// stdafx.cpp : 只包括标准包含文件的源文件
// 学生成绩管理系统.pch 将作为预编译头
// stdafx.obj 将包含预编译类型信息

#include "stdafx.h"

// TODO: 在 STDAFX.H 中
// 引用任何所需的附加头文件,而不是在此文件中引用

原创粉丝点击