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.
Showing posts with label CSE1002:PP7. Show all posts
Showing posts with label CSE1002:PP7. Show all posts

Tuesday, 26 April 2016

CSE1002:PP7:DOUBLE ENDED QUEUE

UML:




CODE:


template<class T>
queue<T>::~queue()
{}
template<class T>
queue<T>::queue()
{front=0;
rear=-1;
capacity=20;
ele=new T[20];
}
template<class T>
bool queue<T>::isempty()
{return rear<front;}
template<class T>
bool queue<T>::isfull()
{return capacity<rear-front+1;}
template<class T>
bool queue<T>::enqueue(T data)
{*(ele+rear-front+1)=data;
return *(ele+ rear++ +1)==data;}
template<class T>
T queue<T>::dequeue()
{
if(rear<front)
 ERR_Flag=true;
else
 return *(ele+front++);
}
template<class T>
void queue<T>::print()
{
if(rear<front)
 cout<<"Queue is empty\n";
else
for(int i=front;i<=rear;i++)
 cout<<*(ele+i)<<endl;
}
template<class T>
bool deque<T>::push_Back(T data)
{
return this->enqueue(data);
}
template<class T>
bool deque<T>::push_Front(T data)
{
T*A =new T[20];
*A=data;
for(int i=this->front;i<=this->rear;i++)
 *(A+i+1)=*(this->ele+i);
this->ele=A;
this->front=0;
this->rear++;
return this->rear<=20;
}
template<class T>
T deque<T>::pop_Front()
{
return this->dequeue();
}
template<class T>
T deque<T>::pop_Back()
{
if(this->rear<this->front)
 ERR_Flag=true;
else
return *(this->ele+this->rear--);
}

CSE1002:PP7:SOLAR

UML:





CODE:


void bag::get()
{
cin>>name>>num_Of_Items;
for(int i=0;i<num_Of_Items;i++)
 cin>>item_Wt[i]>>item_Count[i];
}
void bag::print()
{cout<<name<<endl;}
float bag::compute()
{float f;
for(int i=0;i<num_Of_Items;i++)
 f+=item_Wt[i]*item_Count[i];
return f;
}
bool wayToSort(int i,int j)
{return true;}
void solar::get()
{
cin>>num_Bags;
bag temp;
for(int i=0;i<num_Bags;i++)
{
 temp.get();
 m1[temp.compute()]=temp;
 v.push_back(temp.compute());
}
}
void solar::sort_Vec()
{sort(v.rbegin(),v.rend());}
void solar::print_In_Order()
{
for(int i=0;i<v.size();i++)
 m1[v[i]].print();
}

CSE1002:PP7:List Of points

LIST OF POINTS
QUESTION:

Design a class point with datamembers name of the point(string), value in x-axis and value in y-axis. Provide functions to get the details of a point, print the details of a point and a function to compute distance between the point and a given point. Design a class mobileSpace, with a list of points representing the latitude and longitude of the mobile towers and a point to represent a mobile phone, provide member functions to get details and determine the tower that shall be connected to the phone. Use STL for implementation.

UML:



CODE:

void point::get()
{
cin>>name;
cin>>x>>y;
}
void point::print()
{
cout<<name<<endl;
}
float point::dist(point p)
{
return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
void mobile::get()
{
cin>>num_Tower_Pts;
int i;
for(i=0;i<num_Tower_Pts;i++)
{
point temp;
temp.get();
tower_Pts.push_back(temp);
}
mobile_Pt.get();
}
point mobile::find_Min()
{
int i;
float minv=100000000000000000000000000.0;
point minp;
list<point>::iterator it = tower_Pts.begin();
for(i=0;i<num_Tower_Pts;i++)
{
if(mobile_Pt.dist(*it)<minv)
{
minv=mobile_Pt.dist(*it);
minp=*it;
}it++;
}
return minp;

}

CSE1002:PP7: SYMMETRIC MATRIX

SYMMETRIC MATRIX

Given a square matrix check if it is symmetric or not. Represent a matrix as a vector of vectors. Use vector in STL to represent a matrix.


PSEUDOCODE:


START
Read n
INITIALIZE 2d VECTOR m i.e. vector<vector<int> > m(n,vector<int>(n,0));
SET f=1;
INITIALIZE COLUMN VECTOR i.e. vector<int> col;
FOR j=0 to n-1
CLEAR COL i.e. col.clear();
FOR i=0 to n-1
READ t
PUSH t into col
END FOR
PUSH col into m
END FOR
FOR i=0 to n-1
FOR j=0 to n-1
IF(m[i][j]!=m[j][i] && f==1) THEN
PRINT "Not symmetric";
SET f=0
END IF
END FOR
END FOR
IF(f==1) THEN
PRINT"Symmetric"

STOP


CODE:


#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
cin>>n;
vector<vector<int> > m(n,vector<int>(n,0));
int i;
int j;
int f=1;
vector<int> col;
for(j=0;j<n;j++)
{
col.clear();
int t;
for(i=0;i<n;i++)
{cin>>t;
m[j][i]=t;
col.push_back(t);
}
m.push_back(col);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
//cout<<m[i][j]<<" , "<<m[j][i]<<endl;
if(m[i][j]!=m[j][i] && f==1)
{
cout<<"Not symmetric";
f=0;
break;
}
}
}
if(f==1)
cout<<"Symmetric";
return 0;

}

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";

}