
作业社区
探索学习新天地,共享知识资源!
weixin_慕哥3021856 的学生作业:
// piece.hpp #ifndef __PIECE_HEAD_H_ #define __PIECE_HEAD_H_ #include using namespace std; class Piece { public: Piece(const string &color, int x, int y): x(x), y(y), color(color){} int getX(void) const { return x; } int getY(void) const { return y; } string getColor(void) const { return color; } virtual void showPiece(void) const = 0; protected: int x; int y; string color; }; #endif // blackpiece.hpp #ifndef __BLACKPIECE_HEAD_H #define __BLACKPIECE_HEAD_H #include #include "piece.hpp" using namespace std; class BlackPiece:public Piece { public: BlackPiece(int x, int y):Piece("black", x, y){} void showPiece(void) const { fprintf(stderr, "\033[%d;%dH\033[47;30m● \033[0m", y, x); fprintf(stderr, "\033[%d;%dH\n", y, x+1); } }; #endif // whitepiece.hpp #ifndef __WHITEPIECE_HEAD_H #define __WHITEPIECE_HEAD_H #include #include "piece.hpp" using namespace std; class WhitePiece:public Piece { public: WhitePiece(int x, int y):Piece("white", x, y){} void showPiece(void) const { fprintf(stderr, "\033[%d;%dH\033[47;30m○ \033[0m", y, x); fprintf(stderr, "\033[%d;%dH\n", y, x+1); } }; #endif // main.cpp #include "blackPiece.hpp" #include "whitePiece.hpp" int main(int argc, const char *argv[]) { BlackPiece bkp(10, 10); bkp.showPiece(); WhitePiece wtp(12, 10); wtp.showPiece(); WhitePiece wtp2(10, 11); wtp2.showPiece(); return 0; } 【图片】





风_往北吹 的学生作业:
#include struct student { char name[20]; int id; int score; }st1 = {"jack",1,100}; int main() { struct student st[3]= { {"rose",2,70}, {"lilei",3,60}, {"hmn",4,50} }; int id; //输出st1整个人的信息; printf("NAME\tID\tSCORE\n"); printf("%s\t%d\t%d\n",st1.name,st1.id,st1.score); //输出st中3个的信息; int len = sizeof(st) / sizeof(st[0]); for (int i = 0; i < len; i++) { printf("%s\t%d\t%d\n", st[i].name, st[i].id, st[i].score); } //键盘输入id,判断用户输入的id在st中是否存在 int flag = 0; printf("请输入ID\n"); scanf("%d",&id); for (int i = 0; i < len; i++) { if (id == st[i].id) { flag = 1; printf("%d ID对应学生姓名为:%s\n",id,st[i].name); break; } } if (flag==0) { printf("no exist!"); } return 0; 【图片】





风_往北吹 的学生作业:
head.h #ifndef __HEAD_H__ #define __HEAD_H__ #include extern int m; extern int n; extern int add(); extern int sub(); extern int mul(); extern int div(); #endif calc.c #include "head.h" int m = 30; int n = 10; int add() { return m + n; } int sub() { return m - n; } int mul() { return m * n; } int div() { return m / n; } main.c #include "head.h" int main() { int sum, difference, product, quotient; sum = add(); difference = sub(); product = mul(); quotient = div(); printf("add:%d\n", sum); printf("sub:%d\n", difference); printf("mul:%d\n", product); printf("div:%d\n", quotient); return 0; } 【图片】




