计算机类21-1.2班 实验4

#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;
}
凉心哥哥的小宝藏 文章被收录于专栏

c++

全部评论
``` #include <iostream> using namespace std; #include<bits> #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; } ```</int></vector></bits></iostream>
点赞 回复 分享
发布于 2022-05-02 16:52

相关推荐

09-17 20:37
已编辑
长沙学院 Java
涂莱:学院本重心后移,金10银11,甚至金11银12,战线拉长一点,对于学院本来说秋招是个持久战,加油吧
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务