C++急问......
时间:2014-01-23
来源:互联网
student names. If there are multiple students having the same name, the one with smaller
student ID is listed first. The list is displayed with the format below:
Student ID Student Name Engineering Science
-----------------------------------------------------------------
12345678A Chan Tai Man, Peter 24 17 (Granted)
12333344A Lee Mei Lai 19 (Rejected) 23
14556678A Ng Fat Tat 19 (Rejected) 17 (Rejected)
13982646A Wong Ling Ling, Mary 22 (Granted) 18 (Rejected)
有无人知道其实系点打个CODE?
作者: 0天疯 发布时间: 2014-01-23
作者: Susan﹏汪汪 发布时间: 2014-01-23
#include<cmath>
#include<fstream>
#include<iomanip>
#include<cstdlib>
#include<string>
#include<cstring>
using namespace std;
const int MAXSTUD = 1000;
int arraysize[MAXSTUD] = {};
int counta;
int num = 0;
class Student
{
public:
Student ()
{ //initialize the number of subjects student have.
count = 0; //count the no. of subjects student have.
}
void Inputfile(char words[]);
void Showdata(){
for (unsigned int i = 0;i < strlen(name);i++)
cout << name;
cout << '\t';
for (int i = 0;i < 9;i++)
cout << ID;
for (int i = 0;i < count;i++)
{
cout << '\t';
for (int j = 0;j < 6;j++)
cout << subcode[j];
cout << '\t';
for (int j = 0;j < 2;j++)
cout << grade[j];
}
}
void Switchdata()
{
if ( counta == 0)
for (unsigned int i = 0;i < strlen(name);i++)
before = name;
else {
for (unsigned int i = 0;i < strlen(name);i++)
after = name;
int i = 0;
for (; before == after; i++)
;
if (before > after)
{
int hold = 0;
hold = arraysize[counta - 1];
arraysize[counta - 1] = arraysize[counta];
arraysize[counta] = hold;
}
else if (before < after)
;
else
cout << "Error: There are two students having the same name.";
for (int i = 0;i < 30;i++)
before = after;
}
}
void List_name()
{
for (int i = 0; i < 9; i++)
cout << ID;
for (int i = 0; i < 6; i++)
cout << " ";
for (unsigned int i = 0; i < strlen(name); i++)
cout << name;
for (unsigned int i = 0; i < 25 - strlen(name); i++)
cout << " ";
calculate_GPA();
cout << fixed << setprecision(2) << GPA << endl;
}
void calculate_GPA()
{
int Total_Weight = 0;
double Total_marks = 0;
int weight = 0;
for (int i = 0;i < count;i++)
{
if (subcode[2] == '1')
{
if(subcode[5] == '1' || subcode[5] == '2' || subcode[5] == '3' ||
subcode[5] == '4' || subcode[5] == '5')
weight = 1;
Total_Weight += 1;
}
else if (subcode[2] == '2')
{
if (subcode[5] == '1' || subcode[5] == '2' || subcode[5] == '3' ||
subcode[5] == '4' || subcode[5] == '5')
weight = 2;
Total_Weight += 2;
}
else if (subcode[2] == '3')
{
if (subcode[5] == '1' || subcode[5] == '2' || subcode[5] == '3' ||
subcode[5] == '4' || subcode[5] == '5')
weight = 3;
Total_Weight += 3;
}
else
cout << "Error: Subject does not exists.";
if (grade[0] == 'A' && grade[1] == '+')
Total_marks += 4.5 * weight;
else if (grade[0] == 'A' && grade[1] == '\0')
Total_marks += 4 * weight;
else if (grade[0] == 'B' && grade[1] == '+')
Total_marks += 3.5 * weight;
else if (grade[0] == 'B' && grade[1] == '\0')
Total_marks += 3 * weight;
else if (grade[0] == 'C' && grade[1] == '+')
Total_marks += 2.5 * weight;
else if (grade[0] == 'C' && grade[1] == '\0')
Total_marks += 2 * weight;
else if (grade[0] == 'D' && grade[1] == '+')
Total_marks += 1.5 * weight;
else if (grade[0] == 'D' && grade[1] == '\0')
Total_marks += 1 * weight;
else if (grade[0] == 'F' && grade[1] == '\0')
Total_marks += 0 * weight;
else
cout << "Error: there is no such grade.";
}
GPA = Total_marks / Total_Weight;
}
int Getnamelen()
{
return strlen(name);
}
char Getname(int ptr) //get the name to the main program
{
return name[ptr];
}
char GetID(int ptr) //get the ID to the main program
{
return ID[ptr];
}
char Getsubcode(int subno,int ptr) //get the subject code to the main program
{
return subcode[subno][ptr];
}
char Getgrade(int gradeno,int ptr) //get the grade to the main program
{
return grade[gradeno][ptr];
}
int Getcount() //get the number of subjects to the main program
{
return count;
}
double GetGPA() //get the GPA to the main program
{
return GPA;
}
void Changename(char x[],int length)
{
for (int i = 0;i < length;i++)
name = x;
}
void ChangeID(char x[])
{
for (int i = 0;i < 9;i++)
ID = x;
}
void Changesubcode(int subno,int ptr,char x)
{
subcode[subno][ptr] = x;
}
void Changegrade1(int subno,char x[])
{
for (int i = 0;i < 2;i++)
grade[subno] = x;
}
void Changegrade2(int gradeno,int ptr,char x)
{
grade[gradeno][ptr] = x;
}
void Changecount(int no)
{
count = no;
}
void Delete()
{
for (int i = 0;i < 30;i++)
name = '\0';
for (int i = 0;i < 9;i++)
ID = '\0';
for (int i = 0;i < 15;i++)
{
for (int j = 0;j < 6;j++)
subcode[j] = '\0';
for (int j = 0;j < 2;j++)
subcode[j] = '\0';
}
count = 0;
GPA = 0;
}
private:
char name[30]; //Student Name
char ID[9]; //StudentID
char subcode[15][6]; //15 subject code array with 6 character.
char grade[15][2]; //15 subject grade array with 2 character.
int count; //counting the number of subject.
double GPA; //storing the GPA of the student.
};
Student stud[MAXSTUD];
int main()
{
return 0;
}
void Alphabetical_order() //R13
{
system("CLS");
cout << left << endl << endl << setw(13) << "Student ID" << left << setw(23) << "Student Name"
<< left << setw(16) << "Engineering" << left << setw(13) << "Science" << endl;
for (int i = 0; i < 65; i++)
cout << "-";
cout << endl;
for (int i = 0; i < num; i++)
arraysize = i;
for (int j = 0;j < num - 1;j++)
{
for (counta = 0; counta < num ; counta++)
{
stud[arraysize[counta]].Switchdata();
}
counta = 0;
}
for (int i = 0; i < num ; i++)
{
cout << setw(18) << ' ';
stud[arraysize].List_name();
}
cout << endl;
system ("pause");
printARSM();
printARSMinput();
}
作者: 0天疯 发布时间: 2014-01-23
另外,你遇到乜嘢问题?读唔到资料?输出出错?排序出错?
作者: fitcat07 发布时间: 2014-01-23
{
system("CLS");
cout << left << endl << endl << setw(13) << "Student ID" << left << setw(23) << "Student Name"
<< left << setw(16) << "Engineering" << left << setw(13) << "Science" << endl;
for (int i = 0; i < 65; i++)
cout << "-";
cout << endl;
for (int i = 0; i < num; i++)
arraysize = i;
for (int j = 0;j < num - 1;j++)
{
for (counta = 0; counta < num ; counta++)
{
stud[arraysize[counta]].Switchdata();
}
counta = 0;
}
for (int i = 0; i < num ; i++)
{
cout << setw(18) << ' ';
stud[arraysize].List_name();
}
cout << endl;
system ("pause");
printARSM();
printARSMinput();
}
上面果PART...只系出到排序A至Z 跟大细
但系我想要如果个学生名头果一个英文字母系 = 其他学生第一个英文字母既话 就跟ID大细排
E.G CHAN KA CHUN && CHAN XXXX
两个名开首一样 就转用学生ID...
想问一下系咪用IF ELSE STATEMENT...如果系应该点打...唔识...
作者: 0天疯 发布时间: 2014-01-23

方法一
如果只是排第一个字母
只需要比较第一个char
然后比较ID就是了
方法二
预先按ID排列的话
只需要用Name第一个char做比较...做一次stable sorting
[ 本帖最后由 Susan﹏汪汪 於 2013-11-28 08:12 PM 编辑 ]
作者: Susan﹏汪汪 发布时间: 2014-01-23
Algorithm 同 program,楼主边方面有问题?
睇问题,algorithm应该唔难。冇写开C++,用perl应该几个钟写完。
作者: tonii 发布时间: 2014-01-23
Input:
CHAN SHUI 2013012035
LO DAVID 2013012034
CHAN SIU 2013012033
Output:
CHAN SIU 2013012033
CHAN SHUI 2013012035
LO DAVID 2013012034
Current Algorithm:
sorting_key = name
New Algorithm:
sorting_key = surname + student id (eg. CHAN2013012033)
void Alphabetical_order() //R13
{
system("CLS");
cout
作者: a8d7e8 发布时间: 2014-01-23
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28