ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Tuesday 26 April 2016

CSE1002:PP7:VECTOR OF CHARACTERS

VECTOR OF CHARACTERS

QUESTION:
Design a class charVector that has a character vector as datamember. Provide member functions in the class to createVector, duplicateVector, duplicateRevVector and print. Functions shall be defined as follows:
initializeVector – read a string and create a vector of characters
duplicateVector – Add the content of the vector once at the end. For example if the content of charVector is “bat” then after the function is called the content must “batbat”
duplicateRevVector – Add the content of the vector in reverse at the end. For example if the content of charVector is “bat” then after the function is called the content must “battab”
print – Print content of vector, use iterators for traversal
Use the vector class defined in STL for the implementation. Use [] operator in functions duplicateVector, duplicateRevVector and use iterator in print and initializeVector functions.
UML DIAGRAM:

CODE:



void charVector:: initializeVector(string S)
{
vector<char>::iterator it=cv.begin();
int i=0;
while(S[i]!='\0')
{
cv.push_back(S[i]);
it++;
i++;
}

}
void charVector:: dupVector()
{
vector<char> d=cv;
vector<char>::iterator it=d.begin();
while(it!=d.end())
{
cv.push_back(*it);
it++;
}
}
void charVector:: dupRevVector()
{
vector<char> d=cv;
vector<char>::iterator it=d.end();
while(it!=d.begin())
{
it--;
cv.push_back(*it);
}
}
void charVector:: print()
{
vector<char>::iterator it=cv.begin();
while(it!=cv.end())
{
cout<<*it;
it++;
}
cout<<"YES";

}

No comments:

Post a Comment