[問題] 關於class簡單程式的問題
我自己寫了一小段程式,用的是visual c++ 6.0免費版
#include "stdafx.h"
#include <iostream>
using namespace std;
class Score{
public:
set_initial();
int totalscore();
int number;
char name[10];
int chinese,english,math,total;
};
Score::set_initial(){number=chinese=english=math=total=0;}
int Score::totalscore(){
total=chinese+english+math;
return total;
}
int main(int argc, char* argv[])
{
Score student[]={{1,"John",60,70,80,0},{2,"Mary",70,70,60,0},
{3,"Sherry",60,60,90,0}};
for(int index=0;index<3;index++)
cout<<"Total score of student "<<student[index].name<<"is"
<<student[index].totalscore<<endl;
system("PAUSE");
return 0;
}
其實就是三個學生student[]={{1,"John",60,70,80,0},{2,"Mary",70,70,60,0},
{3,"Sherry",60,60,90,0}};都宣告成class student
第一個數字表示學生編號,第二個數字是學生名字,後面試三個成績和要
存三成績總和的地方
我的問題是:
1.此宣告方法好像不能把
int number;
char name[10];
int chinese,english,math,total;
這三個設成private, 因為main沒辦法直接對private做設定, 如果我想要維持
這種三個學生的宣告方式, 又想加入private, 改怎麼進行呢?
2.就算我把所有class內容全部設定成public後(這根本就是struct一樣了)
有個超奇怪的error
atal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more
information
Error executing cl.exe.
student.exe - 1 error(s), 0 warning(s)
啥都沒講究要打發我, 難道是因為我是免費版嗎= =
請問一下各位高手該如何解決呢? 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.120.134.40
→
09/11 00:49, , 1F
09/11 00:49, 1F
→
09/11 01:05, , 2F
09/11 01:05, 2F
推
09/11 01:13, , 3F
09/11 01:13, 3F
→
09/11 01:14, , 4F
09/11 01:14, 4F
→
09/11 01:15, , 5F
09/11 01:15, 5F
→
09/11 01:16, , 6F
09/11 01:16, 6F
→
09/11 01:16, , 7F
09/11 01:16, 7F
→
09/11 01:16, , 8F
09/11 01:16, 8F
→
09/11 01:17, , 9F
09/11 01:17, 9F
→
09/11 01:17, , 10F
09/11 01:17, 10F
→
09/11 01:18, , 11F
09/11 01:18, 11F
→
09/11 01:21, , 12F
09/11 01:21, 12F
→
09/11 01:21, , 13F
09/11 01:21, 13F
→
09/11 01:25, , 14F
09/11 01:25, 14F
→
09/11 01:30, , 15F
09/11 01:30, 15F
→
09/11 01:44, , 16F
09/11 01:44, 16F
→
09/11 01:45, , 17F
09/11 01:45, 17F
→
09/11 01:51, , 18F
09/11 01:51, 18F
→
09/11 01:52, , 19F
09/11 01:52, 19F
→
09/11 02:10, , 20F
09/11 02:10, 20F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章