#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
class Dice{
	public:
		Dice(int n);
		int cast()
		{
		int number=rand()%sides+1;
		return number;	
		}
		private:
			int sides;
};
Dice::Dice(int n)
{
	sides=n;
}
int main()
{
	int x;
	float count=0;
	cin>>x;
	Dice a(40);
	for(int times=0;times<=500;times++)
	{
		srand(times);
		int s=a.cast();
		if(s==x)
		count++;
	}
	float c=count/500;
	cout<<c<<endl;
	return 0;
}

#include<string>
#include<vector>
using namespace std;
class Book{
	public:
		Book(string isbnA,string titleA,float priceA);
		void print();
	private:
	    string isbn;
		string title;
		float price;	
};
Book::Book(string isbnA,string titleA,float priceA)
{
	isbn=isbnA;
	title=titleA;
	price=priceA;
}
void Book::print(){
	cout<<isbn<<"   "<<title<<"   "<<price<<endl;
}
int main()
{
	vector<Book>books;
	string isbn,title;
	float price;
	int i=0;
	while(cin>>isbn>>title>>price){
		Book book(isbn,title,price);
		i++;
		books.push_back(book);
	}
	for(int k=0;k<i;k++)
	{
		books[k].print();
	}
	return 0;
}

#include<string>
using namespace std;
int main()
{
	int a=9; 
	int *p=&a;
	cout<<"The value at p:"<<*p;
	return 0;
}

#include<iostream>
using namespace std;
int fn1(){
	int *p=new int (5);
	return *p;
}
int main()
{
	int a=fn1();
	cout<<"The value of a is:"<<a;
	return 0;
}

课本6—18的题目并不清楚哪里错误,new int(5) 不懂是什么意思 程序运行直接出现结果 不明白错误在哪里。

实验3 不会。