当前位置:网站首页>Vector 1 (classes and objects)
Vector 1 (classes and objects)
2022-06-23 01:01:00 【SZU healing system bug】
Catalog
Title Description
n An ordinal number a1,a2,...,an The array is called n Dimension vector . by n Dimension vector definition CVector class , Contains private data members :
int *data;// Storage n Dimension vector
int n; // Vector dimension .
There are methods : Parameter free constructor , Set up n=5,data The data of each group are 0,1,2,3,4; Constructors , Use virtual parameter n1 And an array a initialization n and data The data of ; Output function , Output... In format n The value of the dimension vector ; Destructor .
Main function input data , Generate CVector Object and call the output function to test .
Input
Input n
Input n Dimension vector
Output
Call the parameterless and parameterless constructors respectively to generate 2 individual CVector object , Output their values .
sample input 1
6
10 1 2 3 4 5
sample output 1
0 1 2 3 4
10 1 2 3 4 5
AC Code
#include<iostream>
using namespace std;
class CVector
{
int * data;
int n;
public:
CVector(){
data=new int[5];
for(int i=0;i<5;i++)
data[i]=i;
n=5;
}
CVector(int n1,int *a){
n=n1;
data=new int[n1];
for(int i=0;i<n1;i++)
data[i]=a[i];
}
void display(){
int i;
for(i=0;i<n-1;i++)
cout<<data[i]<<' ';
cout<<data[i]<<endl;
}
~CVector(){
if(data)
delete[] data;
data=NULL;
}
};
int main() {
int n,i;
cin>>n;
int *p=new int [n];
CVector a;
a.display();
for(i=0;i<n;i++)
cin>>p[i];
CVector b(n,p);
b.display();
if(p)
delete[] p;
p=NULL;
}边栏推荐
- How Huawei cloud implements a global low delay network architecture for real-time audio and video [Part 1]
- 最安全的现货白银的心理分析
- Shell logs and printouts
- Local deployment and problem solving of IIS in ArcGIS JS 4.23
- Steps to implement a container global component
- Ansible learning summary (8) -- Summary of ansible control right raising related knowledge
- 股票在哪个平台买比较安全呢?
- 3dMax建模笔记(一):介绍3dMax和创建第一个模型Hello world
- Database daily question - day 20: selling products by date
- How to calculate the position of gold ETF
猜你喜欢

Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization

Cadence spb17.4 - Allegro - optimiser la spécification de l'angle de connexion de la polyligne pour une seule ligne électrique - polyligne à arc

SAP mm transaction code vl04 create outbound delivery for sto

二叉树转字符串及字符串转二叉树

SAP UI5 应用开发教程之一百零三 - 如何在 SAP UI5 应用中消费第三方库试读版

數據庫中數據的儲存結構和方式是什麼?

【机器学习-西瓜书】更文挑战【Day1】:1.1 引言

Installation record of ros1noetic in Win 11

你踩过这些坑吗?谨慎在时间类型列上创建索引

Explain the startup process of opengauss multithreading architecture in detail
随机推荐
[22 summer reconstruction 1] codeworks round 791 (Div. 2)
Daily question brushing record (I)
Node fetch download file
Binary tree to string and string to binary tree
Sélecteur de hiérarchie
flowable 全局监听 监听流程的启动和流程的结束
Shell 查看帮助
Flink synchronizes MySQL data to es
关于测试/开发程序员技术的一些思考,水平很高超的,混不下去了......
Flowable global listener monitors the start and end of a process
Graphite statsd interface data format description
通过天天基金投资基金安全吗?我打算开户买基金
B tree and b+ tree
图神经网络有哪些用途和应用?
EasyCVR硬件盒子如何设置断电自启动
Shell view help
What is the storage structure and mode of data in the database?
你踩过这些坑吗?谨慎在时间类型列上创建索引
JS prevent the PC side from copying correct links
“听觉”营销价值凸显,喜马拉雅迎来新局点