一个C++的程序设计问题

#include<iostream>usingnamespacestd;classStudent{private:char*name;char*level;intscor... #include<iostream>using namespace std;class Student{private : char *name; char *level; int score1; int score2; int scorez; int scorem; int scoall;public: Student(); ~Student(); void Evaluate(); void Output(); void Input();};Student::Student(){ name = "NoName"; level = "NoLevel"; score1 = 0; score2 = 0; scorez = 0; score1 = 0; scoall = 0;}void Student::Input(){ int s1,s2,sz,sm; char *n; cout<<"请依次输入学生姓名,第一次随堂考试成绩(不超过10),第二次随堂考试成绩(不超过10),期中成绩(不超过100),期末成绩(不超过100)"<<endl; cin>>n>>s1>>s2>>sz>>sm; score1 = s1; score2 = s2; scorez = sz; scorem = sm; name = new char [strlen(n)+1]; strcpy(name,n);}Student::~Student(){ if(name) { delete []name; }}void Student::Evaluate(){ int s1,s2,sz,sm; int all; level = new char[strlen("B")+1]; strcpy(level,"B"); all = (s1+s2)*0.25+sz*0.25+sm*0.5; if(all!<90) { level = new char[strlen("A")+]; strcpy(level,"A"); cout<<"该学生成绩等级为"<<level<<endl; } else if(all>=80 && all<=89) { level = new char[strlen("B")+]; strcpy(level,"B"); cout<<"该学生成绩等级为"<<level<<endl; } else if(all>=70 && all<=79) { level = new char[strlen("C")+]; strcpy(level,"C"); cout<<"该学生成绩等级为"<<level<<endl; } else if(all>=60 && all<=69) { level = new char[strlen("D")+]; strcpy(level,"D"); cout<<"该学生成绩等级为"<<level<<endl; } else if(all>=50 && all<=59) { level = new char[strlen("E")+]; strcpy(level,"E"); cout<<"该学生成绩等级为"<<level<<endl; }}void Student::Output(){ cout<<"学生姓名:"<<name<<'\n'<<endl; cout<<"学生第一次随堂考试成绩:"<<score1<<'\n'<<endl; cout<<"学生第二次随堂考试成绩:"<<score2<<'\n'<<endl; cout<<"学生期中考试成绩:"<<scorez<<'\n'<<endl; cout<<"学生期末考试成绩:"<<scorem<<'\n'<<endl;}int main(void){ Student Array[5]; int i; for(i = 0;i < 5;i++) { Array[i].Input(); Array[i].Evaluate(); } for(i = 0; i < 5;i++) { Array[i].Output(); } return 0;} 展开
 我来答
山水阿锐
2015-05-03 · TA获得超过34.3万个赞
知道顶级答主
回答量:23.7万
采纳率:91%
帮助的人:3.2亿
展开全部
您好,您这样:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int data[26];
char buffer[3];
int num;
FILE *fp = fopen("data.in","r");
memset(data,0,sizeof(data));
while(1)
{
num=fread(buffer,sizeof(char),2,fp);//一次读入2个字符
if(num==2)
{
buffer[2]='\0';
if (buffer[0]>='A'&&buffer[0]<='Z')
{
data[buffer[0]-'A']++;
}
if (buffer[0]>='a'&&buffer[0]<='z')
{
data[buffer[0]-'a']++;
}
if (buffer[1]>='A'&&buffer[1]<='Z')
{
data[buffer[1]-'A']++;
}
if (buffer[1]>='a'&&buffer[1]<='z')
{
data[buffer[1]-'a']++;
}
}
else
if(num==1)
{
if (buffer[0]>='A'&&buffer[0]<='Z')
{
data[buffer[0]-'A']++;
}
if (buffer[0]>='a'&&buffer[0]<='z')
{
data[buffer[0]-'a']++;
}
}
else
break;
}
fclose(fp);
for(num=0;num<26;num++)
printf("%c,%d\n",'A'+num,data[num]);
return 0;
}
程序如上,可以输出结果。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式