#include <iostream>
using namespace std;
class vector1
{
      float vector[];
      int y;
      public : 
             vector1(int x)
             {
                      y=x;
                        cout<<"enter the elements of the array";
                        for(int i=0; i<=y; i++)
                        {
                           cin>>vector[y];
                        }
                           cout<<"elements of vectors are";
                           cout<<"{";
                             for(int i=0; i<y; i++)
                           {
                                   cout<<"\n"<<vector[i];
                           }
                                   cout<<"}";
             }
                                   
                           void modify(int z)
                           { 
                             int a;
                                for(int i=0; i<y; i++)  
                                       {
                                             if(z == vector[i])
                                             {
                                                            a = i;
                                    cout<<"subscript for no u wann reaplace are"<<i;
                                                            return;
                                             }      
                                       }
                                                         cout<<"enter the no u replace";
                                                                 cin>> vector[a];
                             }
          
        
                                                            void multiplication(int p)
                                                                 
                                                               {
                                                               for(int i=0; i<y; i++) 
                                                                                { 
                                                                                       vector[i] = p*vector[i];
                                                                                }
                                                                                    cout<<"after multiplication vector is";
                                                                                         for(int i=0; i<y; i++)
                                 {
                                   cout<<"\n"<<vector[i];
                                   }
                                                                 }
                                   
                                 void display();
                                   };
                                   
                                   
                                   void vector1 :: display()
                                   {
                                       cout<<"{";
                                       for(int i=0; i<y; i++)
                           {
                                   cout<<"\n"<<vector[i];
                                   
                            }                     
                                     cout<<"}";
                                   }
                                
                                
                                   int main()
                                   {
                                      vector1 v1(5);
                                      v1.display();
                                      v1.multiplication(2);
                                      v1.display();
                                      }

I need to make a vector array...of floating type which have following methods
multiplication for scalar multiplication with elements;;
display..
input...

Please review your formatting and then repost it.

line 5: float vector[];
arrays are declared with the star, like this: float* vector; In the constructor you need to allocate memory for the array vector = new float[x]; Change the name vector to something else because vector is the name of a c++ class declared in <vector> header file.

line 5: float vector[];
arrays are declared with the star, like this: float* vector; In the constructor you need to allocate memory for the array vector = new float[x]; Change the name vector to something else because vector is the name of a c++ class declared in <vector> header file.

@ ancient thread thats a syntax for dynamic memory allocation...in c style of coding we used to declare in same fashion as i did..
anway thanks i will try as u said...

Please review your formatting and then repost it.

#include <iostream>
using namespace std;
class vector1
{
      float* bector;
      int y;
      public : 
             vector1(int x)
             {
                      y=x;
                        cout<<"enter the elements of the array";
                        for(int i=0; i<=y; i++)
                        {
                           cin>>bector[y];
                        }
                           cout<<"elements of bectors are";
                           cout<<"{";
                             for(int i=0; i<y; i++)
                           {
                                   cout<<"\n"<<bector[i];
                           }
                                   cout<<"}";
             }
                                   
                           void modify(int z)
                           { 
                             int a;
                                for(int i=0; i<y; i++)  
                                       {
                                             if(z == bector[i])
                                             {
                                                            a = i;
                             cout<<"subscript for no u wann reaplace are"<<i;
                                       return;
                                             }      
                                       }
                            cout<<"enter the no u wanna jiske liye sara sang ho raha h";
                           cin>> bector[a];
                             }
          
          
                            void multiplication(int p)
                                                                 
                              {
                                 for(int i=0; i<y; i++) 
                            { 
                             bector[i] = p*bector[i];
                                  }
                                  cout<<"after multiplication bector is";
                            for(int i=0; i<y; i++)
                                 {
                                   cout<<"\n"<<bector[i];
                                   }
                                                                 }
                                   
                                 void display();
                                   };
                                   
                                   
                                   void vector1 :: display()
                                   {
                                       cout<<"{";
                                       for(int i=0; i<y; i++)
                           {
                                   cout<<"\n"<<bector[i];
                                   
                            }                     
                                     cout<<"}";
                                   }
                                
                                
                                   int main()
                                   {
                                      vector1 v1(5);
                                      v1.display();
                                      v1.multiplication(2);
                                      v1.display();
                                      }

but still its not working

In the constructor you need to allocate memory for the array vector = new float[x];

Where have you done this step that AD indicated?

but still its no providing required output

you used the wrong index value in this loop

cout<<"enter the elements of the array";
                        for(int i=0; i<y; i++) // <<< this should be < y, not <= y
                        {
                           cin>>bector[i]; // <<<< this one
                        }

you used the wrong index value in this loop

cout<<"enter the elements of the array";
                        for(int i=0; i<y; i++) // <<< this should be < y, not <= y
                        {
                           cin>>bector[i]; // <<<< this one
                        }

I was start loosing the hope...thanks a tone man...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.