Commit 1585a82a by 李楚霏

work10

parent 09a3b223
#include"golf.h"
#include<iostream>
Golf::Golf(const char * name, int hc) {
strcpy(this->fullname,name);
this->handicap = hc;
}
Golf::~Golf() {
}
const void Golf::setgolf(const char * name, int hc){
strcpy(this->fullname, name);
this->handicap = hc;
}
const void Golf::showgolf() {
std::cout<<"handi:"<<this->handicap<<"fullname:"<<this->fullname<<"\n";
}
\ No newline at end of file
const int Len = 40;
// struct golf
// {
// /* data */
// char fullname[Len];
// int handicap;
// };
// void setgolf(golf &g, const char * name, int hc);
// int setgolf(golf &g);
// void handicap(golf & g, int hc);
// void showgolf(const golf &g);
class Golf {
private:
char fullname [Len];
int handicap;
public:
Golf(const char * name, int hc);
~Golf();
const void showgolf();
const void setgolf(const char * name, int hc);
};
\ No newline at end of file
#include"golf.h"
#include<iostream>
int main() {
// golf ann;
// setgolf(ann, "ann birdfree", 24);
// golf andy;
// andy.handicap = 36;
// stpcpy(andy.fullname, "Andy");
// setgolf(andy);
const int size = 5;
Golf arr[size] = {
Golf("av", 12),
Golf("bc", 12),
Golf("cc",13),
Golf("tt", 14),
Golf("ee", 15)
};
// int result;
// int i;
// for(i =0; i < size; i++) {
// result = setgolf();
// if (!result) {
// std::cout<<"result undefined";
// break;
// }
// // std::cout<< "result:" <<result<<std::endl;
// }
// int nout = i;
std::cout<<"init:"<<std::endl;
for(int i = 0; i < 5; i++) {
arr[i].showgolf();
}
std::cout<<"re: "<<std::endl;
arr[0].setgolf("avvv", 13);
arr[0].showgolf();
std::cout<<"re2: "<<std::endl;
arr[1].setgolf("bccc",14);
arr[1].showgolf();
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment