Có lỗi thì bạn phải viết ra lỗi gì, ít thì cũng phải có cái đề bài đề bài để còn biết bạn định làm gì tung code kín màn hình thế này, sửa theo trình biên dịch báo lỗi thì bài này đúng là sai loạn xạ, khai báo và dùng một kiểu đơn cử
nhưng khi định nghĩa thì lại
Mã:
float Vector::isEmpty(){return ==0;//chả thấy cái return thế này bao giờ}
Còn nhiều lắm đây bản này chỉ sửa sao cho khi biên dich nó không có lỗi bạn dùng trình dịch cũ hay chương trình cũ hay gì mà khai báo iostream.h thế giờ làm gì còn .h nữa giờ chỉ sửa được sao cho nó chạy tạm thôi còn gì sai(chắc chắn không theo yêu cầu của đề bài) bạn đưa lên đây nhớ bỏ code vào tag đi bạn kimlama đưa link rồi đấy đọc đi mà cho vào đấy, còn bài vẫn giữ nguyên bản để bản để bạn tự sửa lỗi chứ mình là không biết đề yêu cầu thế mà sửa cả. nhớ thêm đề.
Mã:
#include<iostream>#include<conio.h>#include<stdio.h>using std::cout;using std::cin;class Vector{ private: int n; //Number of elements float *data; // public: Vector(); Vector(float*a,int n); ~Vector(); int capacity(); bool contains(float elem); int indexOf(float elem); int lasIndexOf(float elem); float elementAt(int index); bool isEmpty(); float* toArray(); void display(); void clear();}; Vector::Vector(){ cout<<"Enter the number of values you want to input ="; cin>>n; cout<<"enter the value:
"; data=new float[n]; for (int i=0;i<n;i++) { cout<<"Index "<<i<<" value="; cin>>data[i]; }} Vector::Vector(float *a, int N){ this->n=N; data=new float[n]; for (int i=0; i<n;i++) data[i]=a[i];} Vector::~Vector(){ delete data; n=0;} int Vector::capacity(){ return n;} void Vector::clear(){ delete data; n=0;} bool Vector::contains(float elem){ for (int i=0;i<n;i++) if(data[i]==elem) return true; return false;} int Vector::indexOf(float elem){ for(int i=0;i<n;i++) if(data[i]=elem) return i; else return -1;} int Vector::lasIndexOf(float elem){ int i=n-1; for (;i<n;i--); if (data[i]==elem) return i; else return -1;} float Vector::elementAt(int index){ return data[index];} bool Vector::isEmpty(){ return 0;} float* Vector::toArray(){ float *dataOut = new float[n]; dataOut=data; return dataOut;} void Vector::display(){ if(!isEmpty()) for (int i=0;i<n;i++) cout<<"Index"<<i<<"Value="<<std::endl; else cout<<"The Vector empty";} int main(){ Vector Vector1; cout<<"
Elements of Vector1:
"; Vector1.display(); float* dataln=new float[5]; dataln[0]=3; dataln[1]=4;dataln[2]=5;dataln[3]=6;dataln[4]=4; Vector Vector2(dataln,5); cout<<"
Elements of Vector2"; Vector2.display(); if(Vector2.contains(4)) { cout<<"
Vector2 contains element 4
" <<"The index of its first occurence=" <<Vector2.indexOf(4) <<"
The index of its last occurence =" <<Vector2.lasIndexOf(4); } else cout<<"Vector2 does not contain element 4."; cout<<"
Element at index 3 of Vector 2 is"<<Vector2.elementAt(3); float* dataOut = new float[Vector2.capacity()]; dataOut=Vector2.toArray(); cout<<"
dataOut Array:"; for (int i=0;i<Vector2.capacity();i++) cout<<dataOut[i]<<""; cout<<"
Clear Vector2 and test if it's empty then.." <<"
Elements of Vector2:"; Vector2.clear(); Vector2.display(); cout<<"
Test isEmpty function"; if(Vector2.isEmpty())cout<<"
Vector2 is empty."; getch(); return 0;}
Trứng rung điều khiển từ xa Vibrator Spark Of Love Sản phẩm trứng rung bluetooth có điều khiển từ xa này được thiết kế với tông màu Rose Gold viền kim khí trải qua. kích tấc 7,4cm x 3,5cm giúp trứng...
TOP 3 trùy rung điều khiển từ xa...