herrDeng網內搜尋

自訂搜尋

Ads

2016年9月30日 星期五

ex4 C++練習

請建立一個student class

成員有:name(string), math(int), java(int), OS(int)

建構方法

方法有:print(), average()

main 中宣告一個3個student的陣列(用普通C陣列即可)
實作average()方法算 math, java, OS 的平均
利用print方法輸出這3個student的資料(含分數平均)

並依據math, java, OS, average()列出四種排序結果

29 則留言:

B10133186 提到...

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
double av;
student(){}
student(string x,int y,int z,int w ){
name = x;
math = y;
java = z;
OS = w;
av = (y + z + w) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t 平均=" << av << endl;
}
};
int main()
{
student X = student("A", 52, 60, 70);
student Y = student("B", 80, 70, 55);
student Z = student("C", 74, 59, 98);
X.print();
Y.print();
Z.print();
system("Pause");
return 0;
}

B10333049 提到...

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x,int y,int z,int w){
name = x;
math = y;
java = z;
OS = w;
}
double avg(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS <<"\t avg="<<avg()<<endl;
}

};
int main()
{
student x[3];
x[0] = student("你好不好", 20, 40, 50);
x[0].print();
x[1] = student("我好不好", 50, 30, 60);
x[1].print();
x[2] = student("他好不好", 100, 90, 95);
x[2].print();
system("Pause");
return 0;
}

B10333016 提到...

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double avg(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java="<< java << "\t OS=" << OS << "\t avg="<<avg()<<endl;
}
};
int main(){
{
student x[3];
x[0] = student("牠好不好", 90, 80, 70);
x[0].print();
x[1] = student("她好不好", 70, 60, 80);
x[1].print();
x[2] = student("他好不好", 100, 50, 80);
x[2].print();
system("Pause");
return 0;
}

B10333054 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;

}
double avg(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS <<"\t avg="<<avg()<< "\n";

}
};
bool mathbigger(student x,student y){
return x.math > y.math;
}
int main(){
student X[3];
X[0] = student("B10333054",80, 73, 89);
X[0].print();
X[1] = student("B10333049",94, 83,79);
X[1].print();
X[2] = student("B10333016",80,78,100);
X[2].print();
sort(X, X + 3, mathbigger);
system("Pause");
return 0;
}

B10133186 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
double av;
student(){}
student(string x,int y,int z,int w ){
name = x;
math = y;
java = z;
OS = w;
av = (y + z + w) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t 平均=" << av << endl;
}
};
bool mathBigger(student X , student Y)
{
return X.math > Y.math;
}
bool javaBigger(student X, student Y)
{
return X.java > Y.java;
}
bool OSBigger(student X, student Y)
{
return X.OS > Y.OS;
}
bool avBigger(student X, student Y)
{
return X.av > Y.av;
}
void printALL(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{
student X[3];
X[0] = student("A", 52, 60, 70);
X[1] = student("B", 80, 70, 55);
X[2] = student("C", 74, 59, 98);
printALL(X);
cout << "=====math======\n";
sort(X, X + 3, mathBigger);
for (student a : X)
a.print();
cout << "=====java======\n";
sort(X, X + 3, javaBigger);
for (student a : X)
a.print();
cout << "=====OS======\n";
sort(X, X + 3, OSBigger);
for (student a : X)
a.print();
cout << "=====av======\n";
sort(X, X + 3, avBigger);
for (student a : X)
a.print();
system("Pause");
return 0;
}

A10433018 提到...

#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int os;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
os = w;
}
double j(){
return (math + java + os) / 3.00;
}
void print()
{
cout << name << "\t math=" << math << "\t java="
<< java << "\t os=" << os << "\t 平均="<<j()<< "\n";
}

};
bool javaBigger(student X, student Y){
return X.java > Y.java;
}
bool mathBigger(student X, student Y){
return X.math > Y.math;
}
bool osBigger(student X, student Y){
return X.os > Y.os;
}
bool Bigger(student X, student Y){
return X.j() > Y.j();
}

int main()
{
student x[3];
x[0] = student("地平線", 70, 60, 50);
x[1] = student("歡樂天堂", 76, 85, 97);
x[2] = student("補習地獄", 42, 59, 34);
for (int i = 0; i < 3; i++)
{
x[i].print();
}
cout << "==========java===========" << "\n";
sort(x, x + 3, javaBigger);
for (int i = 0; i < 3; i++)
{
x[i].print();
}
cout << "==========math===========" << "\n";
sort(x, x + 3, mathBigger);
for (int i = 0; i < 3; i++)
{
x[i].print();
}
cout << "==========os===========" << "\n";
sort(x, x + 3, osBigger);
for (int i = 0; i < 3; i++)
{
x[i].print();
}
cout << "==========平均數===========" << "\n";
sort(x, x + 3, Bigger);
for (int i = 0; i < 3; i++)
{
x[i].print();
}
system("Pause");
return 0;
}

A10433015 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

class student
{
public:

string name;
int math;
int java;
int OS;

student(){}

student(string z,int x,int c,int v){
name = z; math = x; java = c; OS = v;
}
void print()
{
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS<<"\t 平均="<<and()<<"\n";
}
double and()
{
return( (math + java + OS) / 3.0);
}


};
bool mathBigger(student x, student y)
{
return x.math > y.math;
}
bool javaBigger(student x, student y)
{
return x.java > y.java;
}
bool OSBigger(student x, student y)
{
return x.OS > y.OS;
}
bool avBigger(student x, student y)
{
return x.and() > y.and();
}

void all(student x[3])
{
for (int i = 0; i < 3; i++)
{
x[i].print();
}
}

int main()
{
student x[3];

x[0] = student("哈瞜", 75, 80, 90);
x[1] = student("你好", 80, 70, 60);
x[2] = student("世界", 60, 80, 65);

all(x);
cout << "--------Math-----------" << "\n";
sort(x, x + 3, mathBigger);
all(x);
cout << "--------java-----------" << "\n";
sort(x, x + 3, javaBigger);
all(x);
cout << "---------OS----------" << "\n";
sort(x, x + 3, OSBigger);
all(x);
cout << "--------平均---------" << "\n";
sort(x, x + 3, avBigger);
all(x);
system("Pause");
return 0;
}

b10233109 宋昱璋 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

b10233109 宋昱璋 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

b10233072 黃宥婕 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

b10233102 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

b10233096 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

b10233074 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

b10233095 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

B10233108 林宣瑋 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t av=" << av() << "\n";

}
};
bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{
student X[3];
X[0] = student("王小明", 67, 88, 76);
X[1] = student("陳小華", 83, 67, 68);
X[2] = student("黃少洋", 87, 87, 63);
printlAll(X);
cout << "===========math排============\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

B10433080李偉新 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;

student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){

return(math + java + OS) / 3.0;

};
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\n";

}
};
bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
bool javaBigger(student X, student Y)
{
return X.math > Y.math;
}
bool OSBigger(student X, student Y)
{
return X.math > Y.math;
}
void printAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{
student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printAll(X);
cout << "===========math排=================\n";
sort(X, X + 3, mathBigger);
printAll(X);
cout << "===========java排=================\n";
sort(X, X + 3, javaBigger);
printAll(X);
cout << "===========OS排=================\n";
sort(X, X + 3, OSBigger);
printAll(X);
system("Pause");
return 0;
}

B10533065 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;

}
double avg(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t avg=" << avg() << "\n";

}
};
bool mathbigger(student x, student y){
return x.math > y.math;
}
bool javabigger(student x, student y){
return x.java > y.java;
}
bool OSbigger(student x, student y){
return x.OS > y.OS;
}
bool bigger(student x, student y){
return x.avg() > y.avg();
}
void printAll(student x[3]){
for (int i = 0; i < 3; i++)
x[i].print();
}
int main(){
student X[3];
X[0] = student("B10533065", 81, 73, 88);
X[0].print();
X[1] = student("B10533070", 59, 47, 69);
X[1].print();
X[2] = student("B10533066", 51, 59, 62);
X[2].print();
cout << "==============math==============\n";
sort(X, X + 3, mathbigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "==============java==============\n";
sort(X, X + 3, javabigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "==============os==============\n";
sort(X, X + 3, OSbigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "==============平均==============\n";
sort(X, X + 3, bigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
system("Pause");
return 0;
}

B10533065 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;

}
double avg(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t avg=" << avg() << "\n";

}
};
bool mathbigger(student x, student y){
return x.math > y.math;
}
bool javabigger(student x, student y){
return x.java > y.java;
}
bool OSbigger(student x, student y){
return x.OS > y.OS;
}
bool bigger(student x, student y){
return x.avg() > y.avg();
}
void printAll(student x[3]){
for (int i = 0; i < 3; i++)
x[i].print();
}
int main(){
student X[3];
X[0] = student("B10533065", 81, 73, 88);
X[0].print();
X[1] = student("B10533070", 59, 47, 69);
X[1].print();
X[2] = student("B10533066", 51, 59, 62);
X[2].print();
cout << "==============math==============\n";
sort(X, X + 3, mathbigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "==============java==============\n";
sort(X, X + 3, javabigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "==============os==============\n";
sort(X, X + 3, OSbigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "==============平均==============\n";
sort(X, X + 3, bigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
system("Pause");
return 0;
}

B10433011 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include<algorithm>
using namespace std;
int main();
class student
{
public:
string name;
int math;
int java;
int os;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
os = w;
}
double av(){
return(math + java + os) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t os" << os
<< "\t av="<<av()<< "\n ";
}
};
bool bigger(int x, int y)
{
return x > y;
}
bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
bool javaBigger(student X, student Y)
{
return X.java > Y.java;
}
bool osBigger(student X, student Y)
{
return X.os > Y.os;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{
cout << " ==========================================================\n";
student X[3];
X[0] = student(" 東", 67, 88, 76);
X[1] = student("西", 96, 78, 56);
X[2] = student("南", 66, 50, 77);
printlAll(X);
cout << "============================math==========================\n";
printlAll(X);
cout << "============================java==========================\n";
printlAll(X);
cout << "============================os============================\n";
printlAll(X);
system("Pause");
return 0;
}

B10433092 提到...


#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;

student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){

return(math + java + OS) / 3.0;

};
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\n";

}
};
bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
bool javaBigger(student X, student Y)
{
return X.math > Y.math;
}
bool OSBigger(student X, student Y)
{
return X.math > Y.math;
}
void printAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{
student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printAll(X);
cout << "===========math排=================\n";
sort(X, X + 3, mathBigger);
printAll(X);
cout << "===========java排=================\n";
sort(X, X + 3, javaBigger);
printAll(X);
cout << "===========OS排=================\n";
sort(X, X + 3, OSBigger);
printAll(X);
system("Pause");
return 0;
}

a10433024 提到...

#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int os;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
os = w;
}
double av(){
return (math + java + os) / 3.0;
}
void print(){
cout<< name << "\t math=" << math << "\t java=" << java
<< "\t os=" << os << "\t av="<< av() << "\n";
}
};
bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
bool osBigger(student X, student Y)
{
return X.os > Y.os;
}
bool javaBigger(student X, student Y)
{
return X.java > Y.java;
}
bool avBigger(student X, student Y)
{
return X.av() > Y.av();
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[1].print();
}
int main()
{
student X[3];
X[0] = student("你好不好", 60, 88, 76);
X[1] = student("....", 50, 40, 30);
X[2] = student("123", 80, 70, 60);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
cout << "-----math-------\n";
sort(X, X + 3, mathBigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
cout << "-----os-------\n";
sort(X, X + 3, osBigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
cout << "-----java-------\n";
sort(X, X + 3, javaBigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
cout << "-----av-------\n";
sort(X, X + 3, avBigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
system("Pause");
return 0;
}

A10433036 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" < Y.math;
}
bool javaBigger(student X, student Y)
{
return X.java > Y.java;
}
bool OSBigger(student X, student Y)
{
return X.OS > Y.OS;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{
student X[3];
X[0] = student("你好不", 67, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "============math排============\n";
sort(X, X + 3, mathBigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "============java排============\n";
sort(X, X + 3, javaBigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
cout << "============OS排============\n";
sort(X, X + 3, OSBigger);
for (int i = 0; i < 3; i++){
X[i].print();
}
system("Pause");
return 0;
}

b10233127 提到...

#include
#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java
<< "\t OS=" << OS << "\t av=" << av() << "\n";
}
};

bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
void printlAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{

student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printlAll(X);
cout << "-----------math排--------\n";
sort(X, X + 3, mathBigger);
printlAll(X);
system("Pause");
return 0;
}

B10433103 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;

student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;
}
double av(){

return(math + java + OS) / 3.0;

};
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\n";

}
};
bool mathBigger(student X, student Y)
{
return X.math > Y.math;
}
bool javaBigger(student X, student Y)
{
return X.math > Y.math;
}
bool OSBigger(student X, student Y)
{
return X.math > Y.math;
}
void printAll(student X[3]){
for (int i = 0; i < 3; i++)
X[i].print();
}
int main()
{
student X[3];
X[0] = student("你好不", 68, 88, 76);
X[1] = student("1號", 96, 78, 56);
X[2] = student("2號", 66, 50, 77);
printAll(X);
cout << "----------------math排--------------\n";
sort(X, X + 3, mathBigger);
printAll(X);
cout << "---------------java排----------\n";
sort(X, X + 3, javaBigger);
printAll(X);
cout << "--------OS排--------\n";
sort(X, X + 3, OSBigger);
printAll(X);
system("Pause");
return 0;
}

B10333054范綱傑 提到...

#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
student(){}
student(string x, int y, int z, int w){
name = x;
math = y;
java = z;
OS = w;

}
double avg(){
return (math + java + OS) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS <<"\t avg="<<avg()<< "\n";

}
};
bool mathbigger(student X,student Y){
return X.math >Y.math;
}
bool javabigger(student X, student Y){
return X.java >Y.java;
}
bool OSbigger(student X, student Y){
return X.OS >Y.OS;
}
bool avgbigger(student X, student Y){
return X.avg() >Y.avg();
}
int main(){
student X[3];
X[0] = student("B10333054",85, 73, 89);
X[0].print();
X[1] = student("B10333049",94, 83,79);
X[1].print();
X[2] = student("B10333016",80,78,100);
X[2].print();
cout << "-----math-------\n";
sort(X, X + 3, mathbigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
cout << "-----java-------\n";
sort(X, X + 3, javabigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
cout << "-----OS-------\n";
sort(X, X + 3, OSbigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}
cout << "-----avg-------\n";
sort(X, X + 3, avgbigger);
for (int i = 0; i < 3; i++)
{
X[i].print();
}

system("Pause");
return 0;
}

B10233082 提到...

#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
double av;
student(){}
student(string x,int y,int z,int w ){
name = x;
math = y;
java = z;
OS = w;
av = (y + z + w) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t 平均=" << av << endl;
}
};
int main()
{
student X = student("A", 52, 60, 70);
student Y = student("B", 80, 70, 55);
student Z = student("C", 74, 59, 98);
X.print();
Y.print();
Z.print();
system("Pause");
return 0;
}

B10233073 提到...

#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
double av;
student(){}
student(string x,int y,int z,int w ){
name = x;
math = y;
java = z;
OS = w;
av = (y + z + w) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t 平均=" << av << endl;
}
};
int main()
{
student X = student("A", 52, 60, 70);
student Y = student("B", 80, 70, 55);
student Z = student("C", 74, 59, 98);
X.print();
Y.print();
Z.print();
system("Pause");
return 0;
}

B10233074 提到...

#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
double av;
student(){}
student(string x,int y,int z,int w ){
name = x;
math = y;
java = z;
OS = w;
av = (y + z + w) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t 平均=" << av << endl;
}
};
int main()
{
student X = student("A", 52, 60, 70);
student Y = student("B", 80, 70, 55);
student Z = student("C", 74, 59, 98);
X.print();
Y.print();
Z.print();
system("Pause");
return 0;
}

B10233082 唐偉強 提到...

#include
#include
#include
using namespace std;
class student
{
public:
string name;
int math;
int java;
int OS;
double av;
student(){}
student(string x,int y,int z,int w ){
name = x;
math = y;
java = z;
OS = w;
av = (y + z + w) / 3.0;
}
void print(){
cout << name << "\t math=" << math << "\t java=" << java << "\t OS=" << OS << "\t 平均=" << av << endl;
}
};
int main()
{
student X = student("A", 52, 60, 70);
student Y = student("B", 80, 70, 55);
student Z = student("C", 74, 59, 98);
X.print();
Y.print();
Z.print();
system("Pause");
return 0;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章