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

Tuesday, 26 April 2016

CSE1002:BONUS:SORT POINTS

CSE1002 Sort a Given Set of Points

    Design a OOP model to represent a point in a two dimensional space and overload the operators >>,<<, > and ==. Given 'n' points, design an algorithm and write a C++ code to sort them in desceding order. While sorting a point is said to be greater than the other based on their x-coordinate value. If value of x-coordinate is same for both the points then make a decision based on their value of y-coordinate.

==============================================================

 UML
:


CODE:
istream& operator>>(istream& in,point &p)
{
in>>p.x>>p.y;
return in;
}
ostream& operator<<(ostream& out,point& p)
{
out<<p.x<<endl<<p.y<<endl;
return out;
}
bool point::operator==(point& p)
{
return p.x==x&&p.y==y;
}
bool point::operator>(point& p)
{
if(p.x==x)
 return y>p.y;
return x>p.x;
}
void sort_Points(point *p,int s)
{
point temp;
for(int i=0;i<s;i++)
 for(int j=i+1;j<s;j++)
 if(*(p+j)>*(p+i))
 {temp=*(p+i);
 *(p+i)=*(p+j);
 *(p+j)=temp;}
}

CSE1002:BONUS:GUEST

GUEST
Jegan organizes a family function and invite some of his friends. Many of his friends come prior to the function. Jegan has arranged for their accommodation in a hotel. The rooms are booked as the guest arrive, so the room numbers are not continous and not in any order. Jegan has the room number of the friend who had arrived first. And he has requested his friends to have a room number of the person who arrives next to him. That is the friend who arrived third will have room number of the friend who arrived fourth. The last guest will not have any room number. Given the details of each guest such as name, his room number and room number of the guest who arrived next, and room number of that Jegan has, design an algorithm and write a C++ code to print the names and room numbers to serve a coffee.
Hint: Map in STL can be used for representing the input, room number of the guest may be the key and other two details may be stored as value by representing them as a user defined data type.

UML:


CODE:
void guest::get()
 {
cin>>room_No>>name>>friend_Room_No;
}
 void hotel::get()
 {
cin>>num_Of_Guest;
 guest t;
 for (int i=0;i<num_Of_Guest;i++)
 {
t.get();
 stay_Det[t.room_No]=t;
 }
 cin>>first_Room_No;
 }
 void hotel::serve_Coffee()
 {
int i=first_Room_No;
 while (i!=-1)
 {cout<<stay_Det[i].name<<" "<<i<<endl;
 i=stay_Det[i].friend_Room_No;
 }
}


CSE1002:BONUS:POLYGON

POLYGON
Design an class polygon to represent a polygon in a two dimensional space. Provide member functions to get the details of the polygon and compute area

UML:

CODE:

#include <cmath>
point::point()
{x=y=0;}
void point::get()
{cin>>x>>y;}
ostream& operator<<(ostream& Out,point p)
{
Out<<p.x<<" "<<p.y<<endl;
return Out;
}
void outofrange::what()
{
cout<<"Out of range";
}
polygon::polygon(int n)
{
num_Of_Ver=n;
vertices=new point[n];
}
polygon::~polygon()
{
delete(vertices);
}
void polygon::get()
{
vertices=new point[num_Of_Ver];
for(int i=0;i<num_Of_Ver;i++)
 cin>>(vertices+i)->x>>(vertices+i)->y;

}
point& polygon::operator[](int idx)
{
if(idx>num_Of_Ver)
 throw outofrange();
return *(vertices+idx);
}
double polygon::area()
{
double a;
for(int i=0;i<num_Of_Ver;i++)
 {
 a+=(vertices+i)->x*((vertices+(i+1)%num_Of_Ver)->y);
 a-=(vertices+i)->y*((vertices+(i+1)%num_Of_Ver)->x);
 }
 return abs(a/2);

}


CSE1002:BONUS:Generic Right Shift

CSE1002 Generic Right Shift    

Given a set of 'n' elements and 'r', write a generic function to right shift the set of elements by 'r' position. If the elements are to moved to position greater than 'n' then wrap the shift process to the beginning of the collection. For example, if the set of five elements are 1,7,8,9,12 and value of 'r' is 3 then the set of elements would be 8, 9, 12, 1, 7.

PSUEDOCODE:

DEFINE right_Shift(T a[],int n,int r)
for i->0 to r
   T temp = a[n-1];
   for j->n-2 to 0
       a[j+1]=a[j];
   end for
   a[0]=temp;
end for
end definition



CODE:
#include<iostream>
using namespace std;
template <class T>
void right_Shift(T a[],int n,int r)
{
for(int i=0;i<r;i++)
 {
   T temp = a[n-1];
   for(int j=n-2;j>=0;j--)
       a[j+1]=a[j];
   a[0]=temp;
 }
}