#include <iostream>int main(int argc, char** argv) {int i = 1;int *n ;n=&i;<span style="white-space:pre"> </span>//*n=i 这种赋值方式也可以std::cout<<"i为:"<<i<<std::endl;std::cout<<"n为:"<<n<<std::endl;std::cout<<"*n为:"<<*n<<std::endl; return 0;
}调试截图:从调试结果可以看出,n是地址值,*是取,*n是取值;&是取,&i是取地址值。原文:http://blog.csdn.net/qingbowen/article/details/46469095
https://www.cnblogs.com/DouglasLuo/p/13221356.html这道练习题要求我们使用C++统计输入的字符串中a, e, i, o, u这五个字符及其大写的数量。这里其实不难,使用switch语句对输入的字符串挨个进行判断,即可得出算出这五个字符的数量。 后面练习题要求不仅要统计a, e, i, o, u这五个字符及其大写的数量。练习题还要求统计出空格,制表符, 换行符的数量。这里我百度搜了很久都没有搜到符合我心意的答案。这道题难的地方在于,我...
写一个复数类,实现基本的运算,目的熟悉封装与数据抽象。类的定义#include <iostream>
#include <vector>
usingnamespace std;
class Complex{friend ostream & operator << (ostream & os, const Complex &); //重载输出标识符friend Complex operator + (const Complex&, const Complex &);friend Complex operator - (const Complex&, const Complex &);friend Complex operator * (const Complex&, const Complex &);frien...
保护继承protected:保护继承保护继承:当保护继承时,基类的公有和保护成员变成派生类的保护成员,私有成员不可直接访问! 1 #include <iostream>2 3usingnamespace std;4 5class info {6public:7void setter(int a,int b){8 num = a;9 age = b;
10 }
1112int getter(void) {
13int a = age;
14return a;
15 }
1617void pri(void) {
18 cout << num << endl;
19 cout << age << endl;
20 ...
汇集1000道C语言和C++语言的练习题 (例题、笔试题、编程题、算法设计题),由我亲自配上答案(点此查看)。 语法题我就不出了,那个没意思,看书就可以了。本贴汇集50题 (0000-0050),持续更新...0001. 抽签题
从10个数中随机抽取5个数。(相当于双色球抽签问题)0002. 插入排序
已有10个按增序排列好的整数1,3,5,7,9,11,13,15,17,19。要求把一个整数n插到数组中,保持增序排列。0003. 数学公式类计算题
已经圆柱体的底半...
练习14.9 1 istream &operator >> (istream &is, Sales_data &item)2{3double price;4is >> item.bookNo >> item.units_sold >> price;5if (is)6 item.revenue = item.units_sold * price;7else 8 item = Sales_data();9returnis;
10 }练习14.10a)将一个Sales_data的对象逐一赋值;b)类型不对,类型无法转换导致输入发生错误,Sales_data对象被重置为初始状态;练习14.11有错误,没有给出当输入错误时程序应该给...
练习11.1map他是一个有序的且元素不重样的关联容器,他存放元素的方式是以键值对的方式存放的;vector容器没有什么特别的要求练习11.2list适用于在在任何地方添加删除元素,因为他是个双向的链表;vector适用于需要随机访问的程序,只能在尾后添加元素,在其他位置添加或删除元素效率会很低;代价过大deque适用于在容器首尾添加删除元素且随机访问的程序;map是键值对的集合,他能在查找的同时进行高效的访问;set就是关键字的简单...
第四题 单利和复利// 单利投资和复利投资 本金为100元int count = 1;// 本金int principal = 100;// A的第一年的收获float a_alone = principal * 0.1;// B第一年的收获 利息float b_double = principal * 0.05;// b 收获的总和float b_Allhavest = b_double;while (b_Allhavest < a_alone * count){b_double += b_double * 0.05;b_Allhavest += b_double;cout << "b的利息-------" << b_double << endl;count++;}int year =...
练习6.541int fun(int, int);
2 typedef int (*pf) (int, int);
3 vector<pf> a; 1int funAdd(int i, int j)2{3return i + j;4}5int funDel(int i, int j)6{7return i - j;8}9int funMul(int i, int j)
10{
11return i * j;
12}
13int funDiv(int i, int j)
14{
15return i / j;
16}
171819int main()
20{
21 typedef int (*pf) (int, int);
22 vector<pf> a(2);
23 a[0] = funAdd;
24 a[1] = funDel;
25 a[2]...
问题:有一个生产者,多个消费者,生产者每生产一个,放入队列,多个消费者顺序从队列中取出数据,打印最终结果。分析:首先这题,我本意应该设计成如下模型:生产者单开一个线程,向队列中放入数据,而消费者在锁的保护下,从队列中去数据。但是在实际编程中,发现在队列只有100个数的情况,线程不切换,当队列数据多的时候,会发生切换,但是也不是我所想象的那种随机切换,思考至今,也没有一个合理的解释/(ㄒoㄒ)/~~。最后我把...
// text.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;extern"C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#pragma comment(lib,"lualib.lib")
lua_State * L;
LUALIB_API int textC(lua_State *L)
{if(L == nullptr){return0;}cout<<"This msg from C++"<<endl;return0;
}
LUALIB_API int textC1...
抽象一个点,一个圆,并判断点与圆的关系。(在圆内还是圆外)h文件进行类的声明;cpp文件为类的实现细节;主要注重的细节为:=================================================================================================================================工程代码如下://MyCircle.h
#pragma once
#include"MyPoint.h"
class MyCircle
{
public:void setCir(double x, double y, double r);public:char * judge(double ...
1 #include<iostream>2 #include<iomanip>3usingnamespace std;4#define M 10000 5#define N 10000 6int p=1; 7int func2(int a);8void func(int *a,int n) 9{
10int i,j,k;
11for(j=2;j<=n;j++)
12{
13 k=0;
14for(i=0;i<p;i++)
15 a[i]*=j;
16for(i=0;i<p;i++)
17{
18 a[i]+=k;
19 k=a[i]/M;
20 a[i]%=M;
21}
22if(k)
23{
24 p++;
25 a[p-1]+=k;
26}
27}
28//cout<<a[p-1];29int tempnum=0;
30for(int i=0;i<...
假定一组随机数,然后快速找到第num位置的数#include<iostream>
#include<ctime>
usingnamespace std;#define number 10
#define num 7int main()
{srand((unsigned int)time(NULL));int arr[number];int flag=0;//生成随机数组for (int i = 0; i < number; i++){//生成1~10随机数arr[i]=rand()%number+1;}//显示生成的随机数组for (int i = 0; i < number; i++){cout<<arr[i]<<"\t";flag++;if ((flag%10) == 0){cout<<endl;}}//桶...
练习7.1struct Sales_data {string bookNo;unsigned units_sold = { 0 };double revenue = { 0.0 };
};int main(int argc, char* argv[])
{ Sales_data total;if (cin >> total.bookNo >> total.units_sold >> total.revenue) {Sales_data trans;while (cin >> trans.bookNo >> trans.units_sold >> trans.revenue) {if (total.bookNo == trans.bookNo) {total.revenue += trans.revenue;total.units_sold += trans.units_sold;}...