
作业社区
探索学习新天地,共享知识资源!
wgf1209 的学生作业:
Player.hpp #ifndef GOMOKUGAME_01_PLAYER_HPP #define GOMOKUGAME_01_PLAYER_HPP #include #include #include /* @Author: wjhu8 @Time: 2024-11-14 19:27:37 @name: Player.hpp */ //标准的命名空间 using namespace std; //定义一个玩家类 class Player { public: Player(const string &name, const string &color) : name(name), color(color) { } string getName(void) const { return name; } string getColor(void) const { return color; } virtual bool placeChess(int x, int y) = 0; private: string name; string color; }; #endif //GOMOKUGAME_01_PLAYER_HPP BlackPlayer.hpp #ifndef __BLACKPLAYER_HPP__ #define __BLACKPLAYER_HPP__ #include #include #include #include "Player.hpp" #include "ChessBoard.hpp" #include "BlackChess.hpp" /* @Author: wjhu8 @Time: 2024-11-14 19:40:21 @name: BlackPlayer.hpp */ //标准的命名空间 using namespace std; //下黑棋的玩家类设计 class BlackPlayer : public Player { public: BlackPlayer(const string &name) : Player(name, "black") {} public: bool placeChess(int x, int y) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool ok = chessBoard->isVaildPostion(x, y); if (ok) { chessBoard->placeChess(new BlackChess(x, y)); } return ok; } }; #endif //__BLACKPLAYER_HPP__ WhitePlayer.hpp #ifndef __WHITEPLAYER_HPP__ #define __WHITEPLAYER_HPP__ #include #include #include #include "Player.hpp" #include "ChessBoard.hpp" #include "WhiteChess.hpp" /* @Author: wjhu8 @Time: 2024-11-14 19:33:27 @name: WhitePlayer.hpp */ //标准的命名空间 using namespace std; //下白旗的玩家类设计 class WhitePlayer : public Player { public: WhitePlayer(const string &name) : Player(name, "white") { } bool placeChess(int x, int y) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool ok = chessBoard->isVaildPostion(x, y); if (ok) { chessBoard->placeChess(new WhiteChess(x, y)); } return ok; } }; #endif //__WHITEPLAYER_HPP__ main.cpp #include #include #include #include #include #include //标准算法头文件 #include "head/BlackPlayer.hpp" #include "head/WhitePlayer.hpp" /* @Author: wjhu8 @Time: 2024-11-14 16:39:47 @name: main.cpp */ //标准的命名空间 using namespace std; int main() { //创建棋盘对象 ChessBoard *chessBoard = ChessBoard::getChessBoard(); chessBoard->show();//显示棋盘 BlackPlayer blackPlayer("tiechui"); //黑色棋手 WhitePlayer whitePlayer("cuihua"); //白色棋手 blackPlayer.placeChess(5, 1); whitePlayer.placeChess(5, 3); #if 0 //棋盘 ChessBoard *chessBoard = ChessBoard::getChessBoard(); chessBoard->show(); fprintf(stderr, "\n"); //黑棋子 BlackChess *blackChess = new BlackChess(13, 5); //白棋子 WhiteChess *whiteChess = new WhiteChess(13, 7); chessBoard->placeChess(blackChess); chessBoard->placeChess(whiteChess); //判断棋子的位置是否有效 if (chessBoard->isVaildPostion(5, 1)) { chessBoard->placeChess(new WhiteChess(5, 1)); } #endif fprintf(stderr, "\n"); return 0; } 【图片】





阿大月 的学生作业:
#include enum COLOR { red = 1, green = 2, yellow, blue, black }; int main(int argc, char *argv[]) { int col; printf("Please enter a num to represent the color you want: "); scanf("%d", &col); switch (col) { case 1: printf("This num represents red."); break; case 2: printf("This num represent green."); break; case 3: printf("This num represent yellow."); break; case 4: printf("This num represent blue."); break; case 5: printf("This num represent black."); break; default: printf("The color represented by this number was not found"); break; } return 0; }





阿大月 的学生作业:
#include typedef struct{ unsigned char Red; unsigned char Green; unsigned char Blue; }RGB_t; typedef union { RGB_t rgb; unsigned int value; }PIX_t; int main() { PIX_t pix; pix.rgb.Red = 0X11; pix.rgb.Green = 0X22; pix.rgb.Blue = 0X33; printf("pix.value = %#x\n", pix.value); return 0; }





wgf1209 的学生作业:
Chess.hpp #ifndef __CHESS_HPP__ #define __CHESS_HPP__ #include #include #include /* @Author: wjhu8 @Time: 2024-11-14 16:44:12 @name: Chess.hpp */ //标准的命名空间 using namespace std; // 定义一个Chess(棋子)类 class Chess { public: // 构造函数,初始化棋子的颜色、x轴和y轴坐标 Chess(const string &color, int x, int y) : color(color), x(x), y(y) { } // 获取棋子x轴坐标的方法 int getX(void) const { return x; } // 获取棋子y轴坐标的方法 int getY(void) const { return y; } //获取棋子颜色的方法 string getColor(void) const { return color; } virtual void show(void) const = 0;//纯虚函数-->显示功能 private: int x; // 棋子的x轴坐标 int y; // 棋子的y轴坐标 string color; // 棋子的颜色 }; #endif //__CHESS_HPP__ BlackChess.hpp #ifndef __BLACKCHESS_HPP__ #define __BLACKCHESS_HPP__ #include #include #include #include "Chess.hpp" /* @Author: wjhu8 @Time: 2024-11-14 16:59:44 @name: BlackChess.hpp */ //标准的命名空间 using namespace std; //定义一个BlackChess(黑棋子)类,继承Chess(棋子)类 class BlackChess : public Chess { public: BlackChess(int x, int y) : Chess("black", x, y) {} void show(void) const { fprintf(stderr, "\033[%d;%dH\033[43;34m[☻]\033[0m", getY(), getX() - 1); fprintf(stderr, "\033[%d;%dH", getY(), getX()); } }; #endif //__BLACKCHESS_HPP__ WhiteChess.hpp #ifndef __WHITECHESS_HPP__ #define __WHITECHESS_HPP__ #include #include #include #include "Chess.hpp" /* @Author: wjhu8 @Time: 2024-11-14 17:13:35 @name: WhiteChess.hpp */ //标准的命名空间 using namespace std; class WhiteChess : public Chess { public: WhiteChess(int x, int y) : Chess("white", x, y) {} void show(void) const { fprintf(stderr, "\033[%d;%dH\033[44;36m[☺]\033[0m", getY(), getX() - 1); fprintf(stderr, "\033[%d;%dH", getY(), getX()); } }; #endif //__WHITECHESS_HPP__ main.cpp #include #include #include #include #include #include //标准算法头文件 #include "head/BlackChess.hpp" #include "head/WhiteChess.hpp" /* @Author: wjhu8 @Time: 2024-11-14 16:39:47 @name: main.cpp */ //标准的命名空间 using namespace std; int main() { BlackChess blackChess(10, 5); blackChess.show(); fprintf(stderr, "\n"); WhiteChess whiteChess(11,6); whiteChess.show(); fprintf(stderr, "\n"); return 0; } 【图片】





阿大月 的学生作业:
#include struct student{ char name[20]; int id; int score; }st1 = {"Jack", 1, 100}; int main(int argc, char *argv[]) { struct student st[3] = { {"rose", 2, 70}, {"lelei", 3, 60}, {"hmm", 4, 50} }; int id; // 1. Request to modify the above code to output all information of st1. printf("NAME\tID\tSCORE\n"); printf("%s\t%d\t%d\n", st1.name, st1.id,st1.score); // 2. Output three pieces of infomation from st. int i = 0, st_len = sizeof(st)/sizeof(st[0]); for (i=0;i




