Headlines
Loading...
C++ program to implement vectors using templates.

C++ program to implement vectors using templates.

Write a C++ program to implement vectors using templates.

PROGRAM:
#include <iostream .h=""> 
#include <conio .h="">
const size = 4; //GLOBAL STATIC ASSIGNMENT
template <class t=""> //CREATING TEMPLATE 
class vector
{
T* v; //ASSIGNING POINTER OF TYPE V
public:
vector()
{
int i=0;
v = new T[size];
for(i=0;i<size -="" 0="" a="" array="" as="" elements="" for="" i="" input="" int="" operator="" size="" sum="" t="" taken="" the="" this="" v="" values="" vector="" with="" y="" zero=""> v[i] * y. v[i]; 
//PERFORMING SCALAR OPERATIONS 
//x[3] ={a,b,c} a,b,c are +ve numbers
//y[3]={p,q,r} p,q,r are +ve numbers
  // sum = (a*p)+(b*q)+(c*r) 
 
return sum; 
     //RETURNS THE SCALAR PRODUCT TO THE CALLING FUNCTION
}
};
int main()
{
int x[size],p,q,y[size];
clrscr();
        cout&lt;&lt;"\n www.adkool.com";
cout&lt;&lt;"\n\n";
cout&lt;&lt;"Enter "&lt;<size cin="" endl="" for="" p="0;p&lt;size;p++)" size="" values="">&gt;x[p]; } //INPUTING IN FIRST ARRAY
for(q=0;q<size cin="" q="">&gt;y[q]; } //INPUTING IN SECOND ARRAY
vector <int> v1;
vector <int> v2;
v1=x; //ASSIGNING ARRAY 
v2=y; //TO THE VECTOR
int R = v1*v2;
cout&lt;&lt;"R = "&lt;</int></int></size></size></size></class></conio></iostream>
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***