Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » BeginnersRSS Feeds

write a class to represent a vector (a series of float values)

Posted By: Easy Tutor     Category: C++ Programming     Views: 11681

write a class to represent a vector (a series of float values). Include member functions to perform the following tasks:
1)To Create the Vector
2)To modify the value of a given element
3)To multiply by a scalar value.
4)To display the vector in the form (10,20,30....)
Write a program to test your class

Code for write a class to represent a vector (a series of float values) in C++ Programming

/*www.DailyFreeCode.comDownload Projects, Sourcecodes, Tips and Tricks, Interview FAQs, Hotlinks and more....Logon to www.DailyFreeCode.com*//*write a class to represent a vector (a series of float values).Include member functions to perform the following tasks:1)To Create the Vector2)To modify the value of a given element3)To multiply by a scalar value.4)To display the vector in the form (10,20,30....)Write a program to test your class*/

#include <iostream.h>
#include <conio.h>

intconst size=50;

class vector
{
float d[size];
int s;
public:
void create(void);
void modify(void);
void multiply(void);
void display(void);
};

void vector :: create(void)
{
cout<<"\n\nEnter of Array you want to create:-";
cin>>s;
cout<<"Enter "<<s<<" Real Numbers\n";
for(int i=0;i<s;i++)
       cin>>d[i];
}

void vector :: modify(void)
{
int mfy_value;
float with;
cout<<"\nEnter Location of array at which value is to be modified:-";
cin>>mfy_value;
cout<<"Enter Value with which you want to Replace:-";
cin>>with;
d[mfy_value]=with;
}

void vector :: multiply(void)
{
int mul;
cout<<"\nEnter value with which you want to multiply:-";
cin>>mul;
for(int i=0;i<s;i++)
    d[i]=d[i]*mul;
}

void vector :: display(void)
{
cout<<"\n\nDisplay of Array\n";
cout<<"(";
for(int i=0;i<s;i++)
{
    cout<<d[i];
 if(i!=s-1)
     cout<<",";
}
cout<<")";
}

void main()
{
clrscr();
vector o1;
int choice;
do
{
cout<<"\n\nChoice List\n";
cout<<"1)    To Create Vector Array\n";
cout<<"2)    To Modify Array\n";
cout<<"3)    To Multiply with Scalar value\n";
cout<<"4)    To Display\n";
cout<<"5)    EXIT\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1:    o1.create();
    break;
case 2:    o1.modify();
    break;
case 3: o1.multiply();
    break;
case 4: o1.display();
    break;
case 5:goto end;
}
}while(1);
end:
}
  
Share: 



Easy Tutor
Easy Tutor author of write a class to represent a vector (a series of float values) is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!