
C++ Primer Plus 6th
雎然
可以接受失败,但是不能接受懒惰
展开
-
14-7.3
#ifndef QUEUETP_H_#define QUEUETP_H_#include <iostream>#include "worker.h"using namespace std;template<typename T>class Queue{public: Queue(int qs) :m_qsize(qs){} ~Queue(); bool isempty() const; bool isfull() const; int queuecoun原创 2020-05-10 18:12:09 · 141 阅读 · 0 评论 -
14.7-2
#pragma once#ifndef WINE1_H_#define WINE1_H_#include <iostream>#include <valarray>#include <string>using namespace std;template <typename T1, typename T2>class Pair{public: Pair(){}; T1 &first(); T2 &second()原创 2020-05-09 23:27:10 · 148 阅读 · 0 评论 -
14.7-1
#pragma once#ifndef WINE_H_#define WINE_H_#include <iostream>#include <valarray>#include <string>using namespace std;template <typename T1,typename T2>class Pair{public: Pair(){}; T1 &first(); T2 &second();原创 2020-05-09 22:23:24 · 197 阅读 · 0 评论 -
课堂练习14-01
#ifndef STUDENT_H_#define STUDENT_H_#include <iostream>#include <string>#include <valarray>class Student{private: typedef std::valarray<double> ArrayDb; std::string ...原创 2020-05-07 21:35:29 · 134 阅读 · 0 评论 -
13.11-4
#ifndef PORT_H_#define PORT_H_#include <iostream>using namespace std;class Port{public: Port(const char* br = "none", const char* st = "none", int b = 0); Port(const Port&p); virtu...原创 2020-05-06 07:43:15 · 133 阅读 · 0 评论 -
13.11-3
#pragma once#ifndef DMA_H_#define DMA_H_#include <iostream>using namespace std;class ABC{public: ABC(); ~ABC(); virtual void View() = 0;protected:private:};class baseDMA :public ...原创 2020-05-05 10:12:25 · 117 阅读 · 0 评论 -
13.11-1
可能发生中断:char m_name[100];class Cd{public: Cd(char * s1, char * s2, int n, double x); Cd(const Cd & d); Cd(); virtual~ Cd(); virtual void Report()const; virtual Cd & operator=(const...原创 2020-05-04 13:50:59 · 163 阅读 · 0 评论 -
12.9-4
总结1:Stack::Stack( )new Item[1]Stack::Stack(int n){ /*错误写法: pitems = new Item[1]; pitems[0] = '\0'; size = 0; top = 0;*/ pitems = new Item[n]; for (int i = 0; i < n; i++) { pitems[i] =...原创 2020-05-02 18:07:51 · 162 阅读 · 0 评论 -
12.9-3
m_company = new char[len+1];如果m_company = new char[len];~stock时发生错误!!!Stock::Stock(char* co, long n , double pr ){ int len = strlen(co); m_company = new char[len+1]; strcpy_s(m_company, len+1 ...原创 2020-05-02 10:54:54 · 122 阅读 · 0 评论 -
12.9-02
问题1-4:拷贝构造函数,赋值操作符的区别strcpy_s,strcat_s,用法原创 2020-05-01 12:54:48 · 218 阅读 · 1 评论 -
12.9-1
错误代码:Cow c2 = c1;调用的拷贝构造函数,不是赋值操作!!!Cow& Cow::operator=(const Cow&c){ /* strcpy_s(m_name,strlen(c.m_name)+1 , c.m_name);*/ delete[]m_hobby; m_hobby = new char[strlen(c.m_hobby) + 1]; s...原创 2020-04-30 22:56:35 · 120 阅读 · 0 评论 -
12.3队列模拟
#ifndef QUEUE_H_#define QUEUE_H_class Customer{public: Customer(){ m_arrive = m_processtime = 0; } void set(long when); long when()const{ return m_arrive; } int ptime()const { return m_process...原创 2020-04-30 16:21:09 · 94 阅读 · 0 评论 -
11.9-5
原题#ifndef STONWET_H_#define STONWET_H_class Stonewt{public: Stonewt(double lbs); Stonewt(int stn, double lbs); Stonewt(); ~Stonewt(); void show_lbs() const; void show_stn() const; //con...原创 2020-04-27 14:50:20 · 139 阅读 · 0 评论 -
11.9-4
#ifndef MYTIME_H_#define MYTIME_H_#include <iostream>class Time{public: Time(); Time(int h, int m = 0); void AddMin(int m); void AddHr(int h); void Reset(int h = 0, int m = 0); Time...原创 2020-04-27 10:31:37 · 122 阅读 · 0 评论 -
11.9-2&3
void main(){ using namespace std; using VECTOR::Vector; srand(time(0)); double direction; Vector step; Vector result(0.0, 0.0); unsigned long steps = 0; double target; double dstep; cout...原创 2020-04-27 09:09:27 · 145 阅读 · 1 评论 -
11.9-1
#include <iostream>#include <cstdlib>#include <ctime>#include <fstream>#include <string>#include "vector.h"using namespace std;void main(){ using namespace st...原创 2020-04-26 23:24:27 · 156 阅读 · 0 评论 -
11.8-4
friend Stonewt operator*(Stonewt &s, double mult);Stonewt operator*(Stonewt &s, double mult){ return Stonewt(s.pounds * mult);} Stonewt s4; s4=s1 * 2.0; s4.show_stn();原创 2020-04-26 22:54:28 · 128 阅读 · 0 评论 -
11-8-1
Stonewt operator *(double n);Stonewt Stonewt::operator *(double n){ Stonewt stemp; stemp.stone +=(pounds*n)/Lbs_per_stn; int temp=0; temp = (pounds*n) % (double)Lbs_per_stn; stemp.pounds = p...原创 2020-04-26 22:37:47 · 96 阅读 · 0 评论 -
10-10-8
区分:bool push(const Item&item); Item&item是参数,不是类的成员#ifndef LIST_H#define LIST_Htypedef unsigned long Item;class list{public: list(); bool isEmpty() const; bool isFull() const; bo...原创 2020-04-24 21:45:39 · 119 阅读 · 0 评论 -
10.10-7
问题1:构造函数中,成员名和参数名class plorg{public: static const int Len = 19; //错误:误用成员函数fullname plorg(fullname = "abc", CI = 50); //正确:name应该是传进来的参 plorg(char *name="abc",int CI=50); void setPlorg...原创 2020-04-24 16:59:52 · 134 阅读 · 0 评论 -
10-10-6
问题1:函数原型和定义,发两次都使用了默认参数删除函数原型(或者函数定义)的默认参数,只需要一个问题2:const ==>不能修改Move#include <iostream>using namespace std;class Move{public: Move(double a = 0, double b = 0); void reset(do...原创 2020-04-24 15:34:16 · 91 阅读 · 0 评论 -
10.10-5
#ifndef STACK_H_#define STACK_H_struct customer{ char fullname[35]; double payment;};typedef customer Item;class Stack{public: Stack(); bool isfull() const; bool isempty() const; bool...原创 2020-04-24 11:46:39 · 146 阅读 · 0 评论 -
10.10-1
#include <iostream>#include <string>using namespace std;class Stock{public: Stock(); Stock(string, char*, double); Stock(const char*client, const char*num, double i); void save...原创 2020-04-23 22:23:29 · 147 阅读 · 0 评论 -
10.11
#include <iostream>using namespace std;void main(){ int a[] = { 1, 2, 3, 4, 5, 6}; int i = 0; cout <<a[i++];//1-->2,先[]再++ cout << a[++i];//++2=3,先++再[] cout << a[...原创 2020-04-23 16:32:58 · 97 阅读 · 0 评论 -
9.6-4
#include <iostream>namespace SALES{ const int QUARTERS = 4; struct Sales { double sales[QUARTERS]; double average; double max; double min; };}void setSales(SALES::Sales&s...原创 2020-04-22 10:48:32 · 109 阅读 · 0 评论 -
9.6-4
#include <iostream>#include <string>using namespace std;struct chaff { char dross[20]; int slag;};//use heapvoid main1(){ int i = 0; auto num = 0; chaff *pstruct = new chaff...原创 2020-04-22 09:48:46 · 122 阅读 · 0 评论 -
9-06-02
#include <iostream>#include <string>using namespace std;const int ArSize = 10;void strcount(string str);void main(){ string str; cout << "Enter a line:\n"; getline(cin, str...原创 2020-04-21 23:25:11 · 118 阅读 · 0 评论 -
9-06-1
#include <iostream>const int len = 40;struct golf { char fullname[len]; int handicap;};int setgolf(golf&g, const char* name, int hc);//int setgolf(golf&g);void handicap(golf&...原创 2020-04-21 22:41:26 · 111 阅读 · 0 评论 -
8-08-7
#include <iostream>using namespace std;template <typename T>void ShowArray(T arr[], int n);template <typename T>void ShowArray(T*arr[], int n);template<typename T>T S...原创 2020-04-20 22:52:31 · 98 阅读 · 0 评论 -
8-08-06
#include <iostream>using namespace std;template <typename T>T maxn(T a[],int n){ T tmp; tmp = a[0]; for (int i = 1; i < n;i++) { if (tmp<a[i]) { tmp = a[i]; } } ...原创 2020-04-20 21:54:56 · 111 阅读 · 0 评论 -
8-08-5
#include <iostream>using namespace std;template <typename T>T max5(T a[])//T max5(T a[5]){ T tmp; tmp = a[0]; for (int j = 1; j < 5; j++) { if (a[j]>tmp) { tmp = a[j...原创 2020-04-20 20:54:08 · 88 阅读 · 0 评论 -
8-08-4
#include <iostream>#include <cstring>#define _CRT_SECURE_NO_WARNINGSusing namespace std;struct stringy { char* str; int ct;};void set(stringy&s1, char*ptesting){ s1.ct = ...原创 2020-04-20 20:09:48 · 108 阅读 · 0 评论 -
7-13-10
#include <iostream>using namespace std;double add(double x, double y){ return x + y;}double substract(double x, double y){ return x - y;}double calculate(double x, double y, double...原创 2020-04-19 12:55:51 · 160 阅读 · 0 评论 -
7-13-9
#include <iostream>#include <string>using namespace std;const int SLEN = 30;struct student{ char fullname[SLEN]; char hobby[SLEN]; int coplevel;};int getinfo(student pa[], ...原创 2020-04-19 11:38:08 · 150 阅读 · 0 评论 -
7_13_7
#include <iostream>using namespace std;double* fill_array(double *begin,double*end){ cout << "fill_array:" << endl; double *tmp; int i = 0; for (tmp = begin; tmp != end; tmp...原创 2020-04-18 19:23:46 · 110 阅读 · 0 评论 -
7-13-6
#include <iostream>using namespace std;void Fill_array(double arr[],int *str){ int i = 0; double n; cout << "input numbers:\n"; while (cin>>n) { arr[i] = n; i++; cout &...原创 2020-04-18 16:47:42 · 115 阅读 · 0 评论 -
7-13编程练习_第三题
#include <iostream>using namespace std; struct box{ char maker[40]; float height; float width; float length; float volume;};void show_box(box b1){ cout << b1.maker << ...原创 2020-04-18 13:50:18 · 453 阅读 · 0 评论 -
第七章 函数——C++的变成模块——编程练习
#include <iostream>using namespace std;//1.inputvoid fun_input(int* grade,unsigned int *number){ cout << "You can enter up to 10 grades( -1 to quit): " << endl; for (int i = ...原创 2020-04-18 10:47:04 · 117 阅读 · 0 评论