溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - C++ - 類別陣列
 

資訊管理系
副教授
温瑞烘


歷程檔案 Portfolio


關於我 About Me

類別陣列

#include <iostream>
  using namespace std;
class Employee {          // 員工
    int  emplid;          // 員工代碼
    char name[20];        // 員工姓名
  public:
    void set_employee(int id,char *na) { // 設定函數
      emplid=id;          // 設定員工代碼 
      strcpy(name,na);    // 設定員工姓名
    }
    void output_empl() {
       cout << "員工代碼" << emplid << " 員工姓名" << name << endl;
    } 
};
int main() {
  int i,id;
  char name[20];
  Employee emp1[10];
  for (i=0; i<10; i++) {
    cout << "輸入員工代碼:";
    cin >> id;
    cout << "輸入員工姓名:";
    cin >> name;
    emp1[i].set_employee(id,name);
  };
  for (i=0; i<10; i++)   
    emp1[i].output_empl();
}

// 作業:仿照本程式, 輸入10個 員工代碼及員工姓名, 然後以
// 泡末排序法按 員工代碼 由小至大排序
 

全部共 0則留言
登入帳號密碼代表遵守學術網路規範
 


文章分類 Labels

 


最新文章 Top10

中華科技大學數位化學習歷程 - 意見反應