#include <iostream>
using namespace std;
class Point { //Point类定义
public: //外部接口
Point(int x = 0, int y = 0) : x(x), y(y) { //构造函数
count ++;
}
Point(const Point &p) : x(p.x), y(p.y) { //拷贝构造函数
count++;
}
~Point() { count--; }
int getX() const { return x; }
int getY() const { return y; }
static int count; //静态数据成员声明,用于记录点的个数
private: //私有数据成员
int x, y;
};
int Point::count=0;
//静态数据成员定义和初始化,使用类名限定
int main() { //主函数实现
int *ptr = &Point::count; //定义一个int型指针,指向类的静态成员
Point a(4, 5); //定义对象a
cout << "Point A: " << a.getX() << ", " << a.getY();
cout << " Object count = " << *ptr << endl; //直接通过指针访问静态数据成员
Point b(a); //定义对象b
cout << "Point B: " << b.getX() << ", " << b.getY();
cout << " Object count = " << *ptr << endl; //直接通过指针访问静态数据成员
return 0;
}
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int n, a[30], i; // 定义变量及数组,n-销售额个数,a-销售额
cin >> n; // 输入销售额数量,n <= 30
// 输入n个销售额,分别存入a[0]到a[n-1]
for(i = 0; i < n; i++)
cin >> a[i];
// 请在此添加代码,计算并输出销售额的波动情况
/********** Begin *********/
for (int i = 1; i < n; i++) {
cout << a[i] - a[i - 1] << " ";
}
/********** End **********/
return 0;
}
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
#include<vector>
vector<int>v;
int sum = 0;
int main() {
int table[3][4] = { {1,2,3,4},{2,3,4,5},{3,4,5,6} };
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
int x = table[i][j];
v.push_back(x);
}
}
printf("Sum of row 1 is %d\n", accumulate(v.begin(),v.begin()+4,0));
printf("Sum of row 2 is %d\n", accumulate(v.begin()+4, v.begin() + 8, 0));
printf("Sum of row 3 is %d\n", accumulate(v.begin()+8, v.begin() + 12, 0));
return 0;
}