
c++学习
代维7
这个作者很懒,什么都没留下…
展开
-
实验四 继承
实验二task2.cpp#include <iostream>#include <typeinfo>// definitation of Graphclass Graph{public: virtual void draw() { std::cout << "Graph::draw() : just as an interface\n"; }};// definition of Rectangle, der...原创 2021-11-25 12:59:43 · 785 阅读 · 0 评论 -
实验2 数组、指针与C++标准库
task5Info.hpp#include<iostream>#include<string>using namespace std;class Info{public: Info(string name = "",string con = "",string ci = "",int nu = 0):nickname{name},contact{con},city{ci},n{nu}{} ~Info() = default; v...原创 2021-10-30 22:40:37 · 996 阅读 · 0 评论 -
c++实验报告——用户类User
设计并实现一个用户类User,并在主函数中使用和测试这个类。具体要求如下: 数据成员 每个用户有用户名(name)、密码(passwd)、联系邮箱(email)三个属性。 还有一个类属性,用于记录用户总数n。 函数成员 构造函数 如果定义用户对象时未设置密码和邮箱,密码默认为6个1,联系邮箱默认为空串。 成员函数 set_email() 设置邮箱。提示用户从键盘输入邮箱。 change_passwd() 修改密码。修改密码前,要求先输入旧的密码,验证无误后,才允许原创 2021-10-21 18:54:05 · 2275 阅读 · 0 评论 -
c++实验报告——复数类Complex
不使用C++标准库,自行设计并实现一个复数类Complex,使其满足如下要求: 数据成员 用来表示复数的实部real和虚部imag,实部、虚部,均为小数形式。 函数成员 构造函数 支持以下方式定义复数对象: 成员函数 get_real() 返回复数实部 get_imag() 返回复数虚部 show() 用于输出复数。要求以 3 + 4i , 3 - 4i 这样的形式输出 add() 用于把一个复数加到自身,比如 c1.add(c2) ,相当于 c1 += c2 友原创 2021-10-21 18:50:18 · 3189 阅读 · 0 评论 -
第5周cplus作业:设计圆类
设计并实现一个圆类Circle,具体要求如下: 数据成员 center用于表示圆心坐标,是一个Point类的对象 radious 用于表示半径。要求半径可以取小数。 函数成员 带有两个参数,一个参数用于传递圆心信息,一个参数用于传递半径 当创建Circle类对象时,如果没有指定半径,默认半径取值10.0 比如,这样定义Circle类对象: Circle c(p1); 或 Circle c(p1, 5); 带有三个参数,前两个参数分别表示圆心的坐标,第三个参数用于传递半径原创 2021-10-10 21:21:38 · 852 阅读 · 0 评论 -
c++week4设计并实现一个矩形类Rectangle
#include <iostream>#include <iomanip>// 矩形类Rectangle的定义和实现// 补足代码// ×××class Rectangle{public: Rectangle(); Rectangle(int l, int w); Rectangle(const Rectangle &x); double len(); double wide(); do...原创 2021-10-01 14:22:59 · 2205 阅读 · 0 评论 -
c++函数分类以及调用
#include<bits/stdc++.h>using namespace std;//1.构造函数分类和调用//按参数分类 无参构造(默认) 有参构造//类型分类 普通构造 拷贝构造class Person{public: //构造函数 Person() { cout << "无参函数调用" << endl; } Person(int a) { age = a; .原创 2021-09-30 14:01:00 · 267 阅读 · 0 评论 -
c++构造函数和析构函数
#include<iostream>using namespace std;//对象初始化和清理//1 构造函数,进行初始化操作class Person{public: //1.构造函数 //无返回值 无void //函数名和类名相同 //构造函数可以有参数,可以发生重载 //创建对象时,构造函数自动调用,且调用一次 Person() { cout << "Person的构造函数调用" <.原创 2021-09-29 14:42:42 · 95 阅读 · 0 评论 -
c++封装案例——判断两立方体是否相等
#include<iostream>using namespace std;//立方体类设计//1.创建立方体类//2.设计属性//3.设计行为:获取面积和体积//4.判断是否相等class Cube{public: //设置 void setL(int l) { m_L = l; } void setW(int w) { m_W = w; } void setH(in.原创 2021-09-29 14:04:41 · 161 阅读 · 0 评论 -
BFS广搜迷宫问题
/* 5 41 1 2 11 1 1 11 1 2 11 2 1 11 1 1 21 1 4 3*/#include<bits/stdc++.h>using namespace std;int a[101][101],v[101][101];struct point{ int x; int y; int step;};queue<point> r;//申请队列int dx[4] = {0, 1, 0, -1};/.原创 2021-09-26 10:47:06 · 113 阅读 · 0 评论 -
c++实现栈与队列
#include<iostream>#include<stack>#include<cstdio>using namespace std;int main(){ stack<int>s; s.push(1); s.push(2); s.push(3); printf("%d\n", s.top()); s.pop(); printf("%d\n", s.top()); s.pop(.原创 2021-09-26 09:07:25 · 103 阅读 · 0 评论 -
cplus_week2_作业
1【简答题】用C++编程实现在屏幕上输出ASCⅡ码为32~127的字符。(不要使用C语言中的printf等,用C++中的输入输出实现)给出程序源码。#include<bits/stdc++.h>using namespace std;int main(){ for(int i = 32;i <= 127;i++) cout<<(char)i; return 0;}2【简答题】用C++编程打印输出九九乘法原创 2021-09-16 14:46:46 · 151 阅读 · 0 评论 -
数据输出精度、宽度、对齐方式控制
#include<bits/stdc++.h>using namespace std;int main(){ double x, y; x = 0.618; y = 3.14159; cout<< x << " " << y << endl; cout<< setprecision(2) << x << " " << y << end.原创 2021-09-10 17:07:30 · 275 阅读 · 3 评论 -
整数的不同进制输出 布尔型输出
#include<bits/stdc++.h>using namespace std;int main(){ int x = 42; cout<< x <<endl;//十进制 cout<< oct << showbase << x << endl;// oct指定以八进制输出,showbase指定 显示前导符0 cout<< hex << x <&l.原创 2021-09-10 16:51:20 · 743 阅读 · 0 评论