为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
学习任务

满足各态历经性的XC 的学生作业:

#ifndef COMMON_H #define COMMON_H typedef char BYTE; typedef int INT; typedef short SHORT; typedef unsigned char WORD8; typedef unsigned short WORD16; typedef unsigned int WORD32; #endif // COMMON_H #ifndef CHESS_H #define CHESS_H #include “common.h” #include #include #include class Chess { private: INT x; INT y; std::string color; public: Chess(const std::string &color, INT x, INT y) : x(x), y(y), color(color) {} INT getx() const { return x; } INT gety() const; std::string getColor() const { return color; } virtual void show() const = 0; ~Chess(); }; Chess::~Chess() { } INT Chess::gety() const { return y; } #endif // CHESS_H #ifndef BLACK_CHESS_H #define BLACK_CHESS_H #include “common.h” #include “chess.h” #include class BlockChess : public Chess { public: BlockChess(INT x, INT y) : Chess(“black”, x, y) {} void show() const override; }; void BlockChess::show() const { fprintf(stderr, “\033[%d;%dH\033[43;35m[☻]\033[0m”, gety(), getx() - 1); fprintf(stderr, “\033[%d;%dH”, gety() + 1, getx()); } #endif // BLACK_CHESS_H #ifndef WHITE_CHESS_H #define WHITE_CHESS_H #include “common.h” #include “chess.h” #include class WhitekChess : public Chess { public: WhitekChess(INT x, INT y) : Chess(“black”, x, y) {} void show() const override; }; void WhitekChess::show() const { fprintf(stderr, “\033[%d;%dH\033[44;35m[☺]\033[0m”, gety(), getx() - 1); fprintf(stderr, “\033[%d;%dH”, gety() + 1, getx()); } #endif // BLACK_CHESS_H #include “blackchess.h” #include “whitechess.h” #include INT main() { BlockChess b(3, 4); WhitekChess w(6, 5); b.show(); w.show(); return 0; }

得分 100
学习任务

慕先生4541263 的学生作业:

#include #include #include #define MAX 10 #define NULL (void *)0 //实际学⽣的存储 struct student { char name[20]; int id; int age; }; typedef struct student datatype_t; typedef struct{ datatype_t buf[MAX]; //定义数组记录班级学⽣每个学⽣的信息。 int n; //学⽣实际到来的个数。 }seqlist_t; seqlist_t *create_empty_seqlist() { seqlist_t *l = (seqlist_t *)malloc(sizeof(seqlist_t)); if (NULL == l) { printf("malloc runs error"); return NULL; } memset(l, 0, sizeof(seqlist_t)); return l; }; int is_full_seqlist(seqlist_t *l) { if(NULL == l) { printf("memory allocation failed"); return -1; } return l -> n == MAX ? 1 : 0; }; void insert_data_seqlist(seqlist_t *l,datatype_t data){ if (NULL == l) { printf("pointer is null"); return; } l -> buf[l -> n] = data; l -> n += 1; }; void printf_data_seqlist(seqlist_t *l) { int i = 0; for (i = 0; i < l -> n; i++) { printf("name=%s\tid=%d\tage=%d", l -> buf[i].name, l -> buf[i].id, l -> buf[i].age); printf("\n"); } }; int is_empty_seqlist(seqlist_t *l) { return l -> n == 0 ? 1 : 0; }; int delete_data_seqlist(seqlist_t *l,datatype_t data) { int i = 0, j = 0; if (is_empty_seqlist(l)) { printf("The sequence list is empty"); return -1; } for (i = 0; i < l -> n; i++) { if (l -> buf[i].id != data.id) { l -> buf[j] = l -> buf[i]; j++; } } l -> n = j; if (j == i) { printf("The data is not in the sequence list"); return -2; } else { printf("The data is deleted successfully\n"); } }; int main() { seqlist_t *l = create_empty_seqlist(); int i = 0; while (!is_full_seqlist(l)) { printf("please enter the students' info: "); datatype_t data; scanf("%s%d%d", data.name, &(data.id), &(data.age)); insert_data_seqlist(l, data); } printf_data_seqlist(l); datatype_t deleted_data; printf("please enter the data to be deleted: "); scanf("%s%d%d", deleted_data.name, &(deleted_data.id), &(deleted_data.age)); delete_data_seqlist(l, deleted_data); printf_data_seqlist(l); free(l); l = NULL; return 0; }

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号