C++ primer plus第六版第12章编程练习

C++ Primer Plus(第六版)编程练习答案 第12章 类和动态内存分配 本章所有编程练习的工程源码可在此处下载(点击此链接下载),供大家参考交流!   1. 对于下面的类声明: class Cow {          char name[20];          char *hobby;          double weight; public:          Cow();          Cow(const char * nm, co... 阅读详情

1.cow.cpp

#include <iostream>
#include <cstring>
#include "Cow.h"
using namespace std;

Cow::Cow()
{
	m_cName[0] = '\0';
	m_cHobby = NULL;
	m_dWeight = 0;
}


Cow::~Cow()
{
	delete[] m_cHobby;
	m_cHobby = NULL;
}
Cow::Cow(const char* nm, const char* ho, double wt) {
	strcpy_s(m_cName,20, nm);
	int len = strlen(ho);
	delete[] m_cHobby;
	m_cHobby = new char[len + 1];
	strcpy_s(m_cHobby,len+1, ho);
	m_cHobby[len] = '\0';
	m_dWeight = wt;
}
Cow::Cow(const Cow& c) {
	strcpy_s(m_cName,20, c.m_cName);
	int len = strlen(c.m_cHobby);
	m_cHobby = new char[len + 1];
	strcpy_s(m_cHobby,len + 1, c.m_cHobby);
	m_cHobby[len] = '\0';
	m_dWeight = c.m_dWeight;
}
Cow& Cow::operator=(const Cow& c) {
	if (this == &c)
		return *this;
	delete[] m_cHobby;
	strcpy_s(m_cName, 20, c.m_cName);
	int len = strlen(c.m_cHobby);
	m_cHobby = new char[len + 1];
	strcpy_s(m_cHobby, len + 1, c.m_cHobby);
	m_cHobby[len] = '\0';
	m_dWeight = c.m_dWeight;
	return *this;
}
void Cow::ShowCow()const {
	cout << "Cow name:" << m_cName << endl;
	cout << "Cow hobby:" << m_cHobby << endl;
	cout << "Cow weight:" << m_dWeight << endl;
}

main函数:

#include <iostream>
#include "Cow.h"

int main()
{
	Cow cow2("lily", "milk", 50);
	Cow cow3 = cow2;
	Cow cow4(cow2);
	cow2.ShowCow();
	cow3.ShowCow();
	cow4.ShowCow();
	return 0;
}

2.string.h:

#include <iostream>
using std::ostream;
using std::istream;
class String
{
public:
  String(const char* s);
  String(const String &);
  String();
  ~String();
  int length()const { return len; }
  String operator + (const String & st)const;
  void StringUp();
  void StringLow();
  int Has(const char c);
  String & operator = (const String &);
  char & operator[](int i);

  friend String operator+(const char* c, const String& st);
  friend bool operator== (const String& st, const String& st2);
  friend std::ostream & operator << (ostream & os, const String & st);
  friend std::istream & operator >> (istream & os, String & st);
private:
  char* str;
  int len;
};

string.cpp:

#include <cstring>
#include <cctype>
#include "String.h"
using std::cout;
using std::cin;

String::String()
{
  int len = 4;
  str = new char[1];
  str[0] = '\0';
}


String::~String()
{
  delete[] str;
}
String::String(const char* s) {
  len = std::strlen(s);
  str = new char[len + 1];
  strcpy_s(str,len+1, s);
}
String::String(const String & st) {
  len = st.len;
  str = new char[len + 1];
  strcpy_s(str,len+1, st.str);
}
String & String::operator = (const String & st) {
  if (this == &st)
    return *this;
  delete[] str;
  len = st.len;
  str = new char[len + 1];
  strcpy_s(str, len+1, st.str);
  return *this;
}
String operator+(const char* c, const String& st) {
	int n = st.len + strlen(c);
	char* t = new char[n + 1];
	strcpy_s(t, n + 1, c);
	strcpy_s(t + strlen(c), st.len + 1, st.str);
	t[n] = '\0';
	return String(t);
}

String String::operator + (const String & st)const {
	int n = st.len + len;
	char* t = new char[n + 1];
	strcpy_s(t, len+1, str);
	strcpy_s(t + len, st.len+1, st.str);
	t[n] = '\0';
	return String(t);
}
void String::StringUp() {
	for (int i = 0; i < len+1; ++i) {
		str[i] = toupper(str[i]);
	}	
}
void String::StringLow() {
	for (int i = 0; i < len+1; ++i) {
		str[i] = tolower(str[i]);
	}	
}
int String::Has(const char c) {
	int n = 0;
	for (int i = 0; i < len + 1; ++i) {
		if (str[i] == c)
			n++;
	}
	return n;
}

char & String::operator[](int i) { return str[i]; }
bool operator== (const String& st, const String& st2) { return (strcmp(st.str, st2.str) == 0); }
std::ostream & operator << (ostream & os, const String & st) { 
  os << st.str;
  return os;
}
std::istream & operator >> (istream & os, String & st) {
  os >> st.str;
  st.len = strlen(st.str);
  return os;
}

题目中的main函数:

#include <iostream>
#include "String.h"
using namespace std;
int main()
{
	String s1(" and I am a C++ student.");
	String s2 = "Please enter your name:";
	String s3;
	cout << s2;
	cin >> s3;
	s2 = "My name is " + s3;
	cout << s2 << ".\n";
	s2 = s2 + s1;
	s2.StringUp();
	cout << "The string\n" << s2 << "\ncontains " << s2.Has('A')
		<< "'A'characters in it.\n ";
	s1 = "red";
	String rgb[3] = { String(s1),String("green"),String("blue") };
	cout << "Enter the name of a primary color for mixing light:";
	String ans;
	bool success = false;
	while (cin>>ans)
	{
		ans.StringLow();
		for (int i = 0; i < 3; ++i) {
			if (ans == rgb[i]) {
				cout << "That's right!\n";
				success = true;
				break;
			}
		}
		if (success)
			break;
		else
			cout << "Try again!\n";
	}
	cout << "Bye!\n";
	return 0;
}

3.stock.h:

#pragma once
#include <iostream>
using namespace std;

class Stock
{
public:
	Stock();
	Stock(const char* co, long n = 0, double pr = 0.0);
	~Stock();
	void Buy(long num, double price);
	void Sell(long num, double price);
	void Update(double price);
	void Show()const;
	const Stock& Top(const Stock& s)const;

	friend ostream& operator<<(ostream& os, const Stock& st);
private:
	char* m_c_company;
	int m_n_shares;
	double m_d_shares;
	double m_d_total;
	void set_total() { m_d_total = m_n_shares * m_d_shares; }
};

stock.cpp:

#include "Stock.h"
Stock::Stock()
{
	//m_str_company = "no names";
	m_c_company = new char[1];
	m_c_company[0] = '\0';
	m_n_shares = 0;
	m_d_shares = 0;
	m_d_total = 0;
}

Stock::~Stock()
{
	delete[] m_c_company;
	m_c_company = NULL;
}
Stock::Stock(const char* co, long n, double pr) {
	int len = strlen(co);
	m_c_company = new char[len+1];
	strcpy_s(m_c_company, len + 1, co);
	m_c_company[len] = '\0';
	if (n < 0) {
		cout << "Number of shares can't be nagative;" << m_c_company << " shares set to 0.\n";
	}
	else
		m_n_shares = n;
	m_d_shares = pr;
	set_total();
}

void Stock::Buy(long num, double price) {
	if(num<0)
		cout << "Number of shares can't be nagative;" << "Transaction is aborted.\n";
	else {
		m_n_shares += num;
		m_d_shares = price;
		set_total();
	}
}
void Stock::Sell(long num, double price) {
	if (num < 0)
		cout << "Number of shares can't be nagative;" << "Transaction is aborted.\n";
	else if (num > m_n_shares) {
		cout << "You can't sell more than you have!" << "Transaction is aborted.\n";
	}
	else {
		m_n_shares -= num;
		m_d_shares = price;
		set_total();
	}
}
void Stock::Update(double price) {
	m_d_shares = price;
	set_total();
}
const Stock& Stock::Top(const Stock& s)const {
	if (s.m_d_total > m_d_total)
		return s;
	else
		return *this;
}
ostream& operator<<(ostream& os, const Stock& st) {
	ios_base::fmtflags orig = os.setf(ios_base::fixed, ios_base::floatfield);
	streamsize prec = os.precision(3);
	os << "Company: " << st.m_c_company << " Shares: " << st.m_n_shares << endl;
	os << " Share Price:$" << st.m_d_shares;
	os.precision(2);
	os << " Total Worth:$" << st.m_d_total << endl;
	os.setf(orig, ios_base::floatfield);
	os.precision(prec);
	return os;
}

4.stack.cpp

#include "Stack.h"
Stack::~Stack()
{
	delete[] m_p_items;
	m_p_items = nullptr;
}
Stack::Stack(int n ) {
	m_p_items = new Item[n];
	m_n_size = n;
	m_n_top = 0;
}
Stack::Stack(const Stack& st) {
	m_n_size = st.m_n_size;
	m_n_top = st.m_n_top;
	m_p_items = new Item[m_n_size];
	for (int i = 0; i < m_n_top; ++i) {
		m_p_items[i] = st.m_p_items[i];
	}
}
bool Stack::IsEmpty()const {	return m_n_top == 0;}
bool Stack::IsFull()const { return m_n_size == m_n_top; }
bool Stack::Push(const Item& item) {
	if (IsFull())
		return false;
	m_p_items[m_n_top] = item;
	m_n_top++;
	return true;
}
bool Stack::Pop(Item& item) {
	if (IsEmpty())
		return false;
	m_n_top--;
	item = m_p_items[m_n_top];
	return true;
}
Stack& Stack::operator=(const Stack& st) {
	m_n_size = st.m_n_size;
	m_n_top = st.m_n_top;
	m_p_items = new Item[m_n_size];
	for (int i = 0; i < m_n_top; ++i)
		m_p_items[i] = st.m_p_items[i];
	return *this;
}

main函数:

#include <iostream>
#include "Stack.h"
using namespace std;
int main()
{

	Stack stack1;
	Stack stack2(5);
	for (int i = 0; i < 5; ++i)
		stack2.Push(i);
	Stack stack3(stack2);
	if (stack2.Push(10))
		cout << "stack2 is full!\n";
	Stack stack4 = stack2;
	for (int i = 0; i < 6; ++i) {
		Item item;
		if (!stack4.Pop(item))
			cout << "stack4 is already empty,it can't pop!\n";
		else
			cout << "stack4 pop " << item << endl;
	}
	return 0;
}

题目中给出的stack.h:

#pragma once
typedef unsigned long Item;
class Stack
{
public:
	Stack(int n = MAX);
	Stack(const Stack& st);
	~Stack();
	bool IsEmpty()const;
	bool IsFull()const;
	bool Push(const Item& item);
	bool Pop(Item& item);
	Stack& operator=(const Stack& st);
private:
	enum {MAX = 10};
	Item* m_p_items;
	int m_n_size;
	int m_n_top;
};

5.题目有问题,应为“希望排队时间不超过1分钟”。按照书中,queue.h:

#pragma once
class Customer
{
public:
  Customer() { arrive = processtime = 0; }
  void set(long when) {
    processtime = std::rand() % 3 + 1;
    arrive = when;
  }
  long when()const { return arrive; }
  int ptime()const { return processtime; }
private:
  long arrive;
  int processtime;
};
typedef Customer Item;

class Queue
{
  struct Node
  {
    Item item;
    struct  Node* next;
  };
  enum { Q_SIZE = 10 };
  Queue(const Queue& q):qsize(0){}
  Queue & operator=(const Queue& q) { return *this; }
public:
  Queue(int qs = Q_SIZE);
  ~Queue();
  bool isfull();
  bool isempty();
  int queuecount()const;
  bool enqueue(const Item& item);
  bool DeleteFirstFromQueue(Item& item);

  private:
  Node * front;
  Node* rear;
  int items;
  const int qsize;
};

queue.cpp:

#include <cstdlib>
#include "Queue.h"

Queue::~Queue()
{
  Node* temp;
  while (front != NULL)
  {
    temp = front;
    front = front->next;
    delete temp;
  }
}

Queue::Queue(int qs):qsize(qs)
{
  front = rear = NULL;
  items = 0;
}
bool Queue::isfull() { return items == qsize; }
bool Queue::enqueue(const Item& item)
{
  if (isfull())
    return false;
  Node* add = new Node;
  add->item = item;
  add->next = NULL;
  items++;
  if (front == NULL)
    front = add;
  else
    rear->next = add;
  rear = add;
  return true;
}
bool Queue::DeleteFirstFromQueue(Item& item) {
  if (front == NULL)
    return false;
  item = front->item;
  items--;
  Node* temp = front;
  front = front->next;
  delete temp;
  if (items == 0)
    rear = NULL;
  return true;
}
bool Queue::isempty() { return items == 0; }
int Queue::queuecount()const { return items; }

main函数:

#include <iostream>
#include <ctime>
#include "Queue.h"
using namespace std;
const int MIN_PER_HR = 60;
bool newcustomer(double x) { return (std::rand()*x / RAND_MAX < 1); }
int main()
{
	srand(time(0));
	cout << "Case Study:Banck of Heather Automatic Teller\n";
	cout << "Enter maximum size of queue:";
	int qs;
	cin >> qs;
	Queue line(qs);
	cout << "Set simulation hours: 100\n";
	int hours = 100;
	long cyclelimit = MIN_PER_HR * hours;
	double perhour = 15;
	double min_per_cust;
	Item temp;
	long turnaway = 0;
	long customers = 0;
	long served = 0;
	long sum_line = 0;
	int wait_time = 0;
	long line_wait = 0;
	double average_wait = 0;
	do {
		min_per_cust = MIN_PER_HR / perhour;
		turnaway = 0;
		customers = 0;
		served = 0;
		sum_line = 0;
		wait_time = 0;
		line_wait = 0;
		average_wait = 0;
		while (!line.isempty())
		{
			line.DeleteFirstFromQueue(temp);
		}

		for (int cycle = 0; cycle < cyclelimit; ++cycle) {
			if (newcustomer(min_per_cust)) {
				if (line.isfull())
					turnaway++;
				else {
					customers++;
					temp.set(cycle);
					line.enqueue(temp);
				}
			}
			if (wait_time <= 0 && !line.isempty()) {
				line.DeleteFirstFromQueue(temp);
				wait_time = temp.ptime();
				line_wait += cycle - temp.when();
				served++;
			}
			if (wait_time > 0)
				wait_time--;
			sum_line += line.queuecount();
		}
		if (served > 0)
			average_wait = (double)line_wait / served;
		cout << "第" << perhour - 14 << "次实验的平均等候时间为:" << average_wait << "分钟,每小时到达的客户数为:" << perhour << "个。\n";
		perhour++;
	} while (average_wait <1);
	return 0;
}

结果为:

6.main函数:

#include <iostream>
#include <ctime>
#include "Queue.h"
using namespace std;
const int MIN_PER_HR = 60;
bool newcustomer(double x) { return (std::rand()*x / RAND_MAX < 1); }
int main()
{
srand(time(0));
	cout << "Case Study:Banck of Heather Automatic Teller\n";
	cout << "Enter maximum size of queue:";
	int qs;
	cin >> qs;
	Queue line(qs);
	Queue line2(qs);
	cout << "Set simulation hours: 100\n";
	int hours = 100;
	long cyclelimit = MIN_PER_HR * hours;
	double perhour = 30;
	double min_per_cust;
	Item temp;
	long turnaway = 0;
	long customers = 0;
	long served = 0;
	long sum_line = 0;
	int wait_time = 0;
	int wait_time2 = 0;
	long line_wait = 0;
	double average_wait = 0;
	do {
		min_per_cust = MIN_PER_HR / perhour;
		turnaway = 0;
		customers = 0;
		served = 0;
		sum_line = 0;
		wait_time = 0;
		wait_time2 = 0;
		line_wait = 0;
		average_wait = 0;
		while (!line.isempty())
		{
			line.DeleteFirstFromQueue(temp);
		}
		while (!line2.isempty())
		{
			line2.DeleteFirstFromQueue(temp);
		}
		for (int cycle = 0; cycle < cyclelimit; ++cycle) {
			if (newcustomer(min_per_cust)) {
				if (line.isfull()&&line2.isfull())
					turnaway++;
				else {
					customers++;
					temp.set(cycle);
					if (line.queuecount() < line2.queuecount())
						line.enqueue(temp);
					else
						line2.enqueue(temp);
				}
			}
			if (wait_time <= 0 && !line.isempty() ) {
				line.DeleteFirstFromQueue(temp);
				wait_time = temp.ptime();
				line_wait += cycle - temp.when();
				served++;
			}
			if (wait_time2 <= 0 && !line2.isempty()) {
				line2.DeleteFirstFromQueue(temp);
				wait_time2 = temp.ptime();
				line_wait += cycle - temp.when();
				served++;
			}
			if (wait_time > 0)
				wait_time--;
			if (wait_time2 > 0)
				wait_time2 -- ;
			sum_line += line.queuecount()+line2.queuecount();
		}
		if (served > 0)
			average_wait = (double)line_wait / served;
		cout << "第" << perhour - 14 << "次实验的平均等候时间为:" << average_wait << "分钟,每小时到达的客户数为:" << perhour << "个。\n";
		perhour--;
	} while (average_wait > 1);

	return 0;
}

 

C++ Primer Plus(第六版)编程练习答案 所有章节汇总 本博客汇总了本人历时一年学完《C++ Primer Plus (第6版)》所做的所有编程练习的答案,供大家学习参考和交流。 以下附上各章节的答案详解博客地址,以及源码工程下载地址。 PS:源码下载大部分都是需要积分的,当时设置的时候好像有点乱,有的是1积分,有的是3积分,最难的第12章和第13章我设置的是不要积分,大家都可以下载下来自己运行一下看看结果。 第 2 章 开始学习C++: ... 阅读详情

相关推荐

C++ Primer Plus(第六版)编程练习答案 第3章 处理数据

本章所有编程练习的工程源码可在此处下载(点击打开下载链接),供大家参考交流!   1. 编写一个小程序,要求用户使用一个整数指出自己的身高(单位为英寸),然后将身高转换为英尺和英寸,该程序使用下划线字符来指示输入位置。另外,使用一个const符号常量来表示转换因子。 本题要求将输入数据转换为不同的表达方式,使用不同的单位。而从单位为英寸,转换为英单位是尺和英寸,就是将原值除以转换比例之间,得...

清水河C罗——Leonardo-Liu 7499

【C++ Primer Plus】第12章 类和动态内存分配

对类成员使用动态内存分配。 隐式和显式复制构造函数。 隐式和显式重载赋值运算符。 在构造函数中使用new所必须完成的工作。 使用静态类成员。 将定位new运算符用于对象。 使用指向对象的指针。 实现队列抽象数据类型(ADT)。

chaiky的博客 1616

C++ Primer Plus(第六版)编程练习答案 第8章 函数探幽

本章所有编程练习的工程源码可在此处下载(点击打开下载链接),供大家参考交流!   1. 编写通常接受一个参数(字符串的地址),并打印该字符串的函数。然而,如果提供了第二个参数(int类型),且该参数不为0,则该函数打印字符串的次数将为该函数被调用的次数(注意,字符串的打印次数不等于第二个参数的值,而等于函数被调用的次数)。是的,这是一个非常可笑的函数,但它让您能够使用本章介绍的一些技术。在一个...

清水河C罗——Leonardo-Liu 5710

c++ primer plus学习笔记_第12章 类和动态内存分配

c++ primer plus>第六版。

编程驴子的博客 2451

cpp-CPrimerPlus6th中文版章后编程练习解答

C Primer Plus 6th 中文版章后编程练习解答

cpp练习答案

C  Primer  Plus  Sixth  Edition  Programming  Exercise  Selected  Answers   1 Chapter  2  Programming  Exercises     PE  2-­‐1   /* Programming Exercise 2-1 */ #include int main(void) { printf("Gustav Mahler\n"); printf("Gustav\nMahler\n"); printf("Gustav "); printf("Mahler\n"); return 0; }

《C++ Primer Plus》第12章:类和动态内存分配(2)

在构造函数中使用new

weixin_40064300的博客 498

《C++程序设计实践教程》(任志鸿版)第12章实验结果.docx

C++11 标准,gcc编译 内含自己写的代码及实验结果,仅供参考, 有问题也可以交流mail:1356199860@qq.com

《C++ Primer Plus》第12章:类和动态内存分配(1)

主要讲了复制构造函数和赋值运算符重载

weixin_40064300的博客 499

OPNET卫星节点仿真避坑指南:为什么你的STK轨道文件导入后位置不对?

本文深入解析OPNET卫星节点仿真中STK轨道文件导入后位置异常的常见问题,揭示坐标系差异(ECI与ECF)、时间基准不匹配等关键因素。通过修改.SA文件头标识、统一时间基准等解决方案,帮助工程师避免仿真失真,提升卫星通信系统仿真的准确性。特别适用于STK与OPNET协同工作的卫星网络仿真场景。

weixin_30335575的博客 600

2024年捡垃圾指南:E5 V3/V4服务器CPU怎么选?从游戏多开到深度学习,附华南X99主板搭配清单

本文详细解析2024年E5 V3/V4服务器CPU的选购策略,涵盖游戏多开、深度学习等多种应用场景。通过对比E5 V3与V4系列的制程、功耗及性能差异,提供高性价比的CPU型号推荐及华南X99主板搭配方案,帮助用户在有限预算下打造高效能工作站。

weixin_42549451的博客 1586

C++ primer plus 第六版 第十二章 编程练习答案

第十二章 编程练习答案 1. //头文件 #ifndef COW_H_ #define COW_H_ class Cow{ private: char name[20]; char * hobby; double weight; public: Cow(); Cow(const char * nm, const char * ho, double wt...

菜鸡harry的博客 3829

PX4(CUAV v6x 飞控)+ QAV250 机架无人机组装测试教学(无人机电机转向不对,如何反转电机?)

本文介绍无人机的组装与飞控调试:1.无人机的硬件组装。2.无人机飞控软件的下载,电机、遥控器、电调的校准与调试。

weixin_74185504的博客 2890

C++ primer Plus(第六版)中文版 编程练习答案 目录(已更新完2~12章)

C++ primer Plus(第六版)编程练习答案 目录(已更新完2~12章) 第二章 开始学习C++ 编程练习答案 https://blog.youkuaiyun.com/weixin_42411044/article/details/85106794 第三章 处理数据 编程练习答案 https://blog.youkuaiyun.com/weixin_42411044/article/details/85...

AirHead 1753

PT静态时序分析实战:从基础命令到高级报告解析

本文详细介绍了PT(PrimeTime)静态时序分析(STA)的实战技巧,从基础命令如pt_shell和report_timing的使用,到高级报告解析与问题排查。通过丰富的实例和脚本示例,帮助工程师快速掌握时序分析的核心技能,提升芯片设计验证效率。

weixin_29289821的博客 954

excel 如何自动调整行间距 vba

EXCEL是一个非常使用的软件,虽然我们平时仅使用他做一些报表,仅此而已;我在工作中,由于很懒,不愿意做考试重复的工作,就想着使用vba的宏来完成重复的工作,这样就能省出一部分的时间来了。本人不喜欢在博客里面写以下教程类的东西,我的理念是将工作中的痛点的解决办法分享出来,以解决问题为主。

sixtome 1316

C.Primer.Plus(第六版)第12章 编程练习

//12.1// cow.h #ifndef COW__H__ #define COW__H__ class Cow { private: static const int N = 20; char name[N]; char *hobby; double weight; public: Cow(); Cow(const char* nm,const

mmdnxh的博客 574

如何免费快速的部署一个自用免VIP的自动追剧工具!NAS新玩法!豆瓣与迅雷结合,轻松实现自动下载电影自动追剧功能(支持Windows,群晖nas,飞牛nas,软路由,服务器等Docker快速部署)

追剧党狂喜!豆瓣追剧神器,自动添加云盘,自动下载,微信通知,一键搞定!

XiaoqiangClub的博客 4583

C++ primer plus(第六版)编程练习答案 第12章 类和动态内存分配

根据实际情况可知,每小时到达的客户数目越多,则平均等候时间越长,若要求平均等候时间为1分钟(即平均等候时间不超过1分钟时的临界情况)对应的每小时到达客户数,则我们可以让程序从每小时客户数从1开始计算(不小于100小时)其对应的平均排队时间,直到平均等待时间刚好超过1分钟的时候停止,此时对应的客户数(或者对应客户数-1)即为答案。请重新编写方法,以适应这种新的表示法,并编写一个程序来演示所有的方法,包括复制构造函数和赋值运算符。定义一个复制构造函数,使初始化复制指针指向的数据,而不是复制指针指向的地址。

吻等离子的博客 1131

Python 爬虫教程:企业官网基本信息抓取

本文介绍了使用Python爬虫技术抓取企业官网信息的方法,包括公司名称、简介、联系方式、地址、产品及新闻等数据。通过Requests和BeautifulSoup库实现网页请求与解析,并利用Pandas存储数据为CSV文件。同时提供了应对反爬虫机制(如设置User-Agent、代理IP池、延迟请求等)的解决方案,帮助高效获取企业公开数据。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1861

【虚幻引擎UE】UE5 阴影异常与优化

【虚幻引擎UE】UE5 阴影异常与优化解决方案合集

灵境引路人 3万+

C++ Primer Plus(第六版)中文版编程练习答案

53 C++ Primer Plus(第六版)第十二章 编程练习答案1BankAccount.hBankAccount.cppBankAccount.cpp2BankAccount.hBankAccount.cppBankAccount.cpp3BankAccount.hBankAccount.cppBankAccount.cpp4BankAccount.hBankAccount.cppBankAccount.cpp5BankAccount.hBankAccount.cppBankAccount.cpp6B

yuandenixin的博客 304

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

C++ Primer Plus(第六版)第12章课后编程答案

1. #ifndef QUEUE_H_ #define QUEUE_H_ class Cow { private: char name[20]; char *hobby; double weight; public: Cow(); Cow(const char *num, const char *ho, double wt); Cow(const Cow &amp; c); ~...

云中自有锦书 925

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

c++ Primer Plus(第六版)第十二章习题,写代码之路

c++ Primer Plus(习题12.1) //12.1头文件 #pragma once #ifndef COW_H #define COW_H #include #include class Cow { private: char name[20]; char *hobby; double weight; public: Cow(); Cow(const char* nm, co

Robot_x的博客 1514

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

c++ primer plus 第六版第十二章编程练习

12.1 //Cow.h class Cow { char name[20]; char *hobby; double weight; public: Cow(); Cow(const char*nm, const char *ho, double wt); Cow(const Cow &amp;c); ~Cow(); Cow&amp;operator=(const Cow &...

Schlangemm的博客 345

C++ Primer Plus 第六版 所有章节课后编程练习答案

C++ Primer Plus 第六版 所有章节课后编程练习答案

xiaojimmychen的专栏 9万+
上一篇: C++primer plus第六版第11章编程练习
下一篇: 敏捷软件开发第26章STAIRWAY TO HEAVEN设计模式C++源码
possible1990
博客等级 码龄17年 0粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值