一個簡單的學生管理系統

來源:互聯網
上載者:User

 

 

工程連結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 中
// 引用任何所需的附加標頭檔,而不是在此檔案中引用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.