Wednesday, 23 August 2017

INTERCEPT VIT WIFI

How to intercept VIT WiFi and get access to blocked websites

Download  Betternet

you can download it from here- 

DOWNLOAD BETTERNET

OR

DOWNLOAD HERE


it gives unlimited access to the VPN

The program comes with just a single button. Click on it to connect and click again to disconnect, that’s it really.
Once connected, we were able to browse any website on the web, connect to any portal without interference. Betternet also allowed us to avoid our ISPs firewall, so for folks who are unable to access Facebook or YouTube due to ISP restriction, this program, should help with crossing the line.
Whether or not Betternet will work for those on a college or university campus where the Internet would likely be restricted, is left to be seen at this point.

Pros:
  • unlimited simultaneous connections
  • fast connection
  • easy to use
  • totally free

Cons:
  • no version for Mac available
  • very limited server selection
  • paid for by third party advertising


you can get the following

1.Access to blocked websites

With Betternet Windows VPN the entire range of blocked websites become accessible on your Chrome web browser. You can access YouTube, Facebook and Twitter everywhere. You will be able to quickly reach all the social networks and news websites that are blocked by government.

 2.Connect to the fastest servers

When you connect to Betternet, it automatically finds the nearest server to you for the best connection experience. By connecting to the fastest server your Internet speed is more stable, and you shouldn't need to worry about slow connection anymore.


3.Protect your online privacy and security

Surfing the web anonymously and securely is one of the most important things for an online user. With Betternet Windows VPN your data and personal information is secured on the web and nobody can track your activity on the Internet. You can confidently use public Wi-fi without being afraid of hackers.



4.Access go-restricted and blocked channels

You may be on a trip and want to watch your favorite TV shows, sports channels, and movies, or maybe listen to your favorite music on music streaming apps. With Betternet VPN for Windows, you can access Netflix, Pandora, Beats 1, BBC iPlayer, and many other websites.

Saturday, 20 May 2017

DUMMY PROGRAMMER QUESTIONS

Questions made by DUMMY PROGRAMMER


Question-Convert a given Decimal number to binary
ANS-
#include<iostream>
#include<string.h>
using namespace std;
void take(long long int  n)
{
    int c=0,i=0,rem=0;
    int m[50];
    do{
        rem=n%2;
        n=n/2;
       m[i]=rem;
        i=i+1;
    }while(n!=0);

    for(int j=i-1;j>=0;j--)
    {
        cout<<m[j];
    }
}
int main()
{
    long long int n;
    string s;
    cin>>n;
    take(n);
    return(0);

}


_________________________________________________________________



Ques-A positive interger N is passes as the input. The program must print the number of 1s in the binary representation of N.
Input format-
input the number N.
Output format-
First line contains the count of 1s in the binary representation of N.
Boundary condition-
1<=N<=9000000000.

Example-
input-22
output-3
Explaination-the binary representation of 22 is 10110. There are three 1s in it.

____________________________________________________________


Solution-

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    unsigned long long int n;
    int i=0;
    cin>>n;
    while(n!=0)
    {
        if(n%2==1)
            i++;
        n=n/2;
    }
    cout<<i;
}



____________________________________________________________

Ques-Take input a string(with spaces) and for each word make sure that the word starts with uppercase and gives alternate lowercase

Example1-

input-Every BoY HaS hiS OWn LoVESTOry
expected output-EvErY BoY HaS HiS OwN LoVeStOrY

Example2-

input-this sEEMS CoOL
expected output-ThIs SeEmS CoOl

______________________________________________________________

Solution-


#include<iostream>

#include<string>
using namespace std;

void convert( string& s)

{
    for(int i=0;i<s.length();i++)
    {
        s[i]=tolower(s[i]);
    }
}

void convertevenodd( string &s)

{
    for(int i=0;i<s.length();i=i+2)
    {
        if(s[i]==' ')
        {
            i=i-1;
        }
        else
        {
        s[i]=toupper(s[i]);
        }
    }
}
int main()
{
    string s;
    getline(cin,s);
    convert(s);
    convertevenodd(s);
    cout<<s;
    return(0);
}


Monday, 1 May 2017

BONUS

BONUS PRACTICE PROBLEMS


Ques-FIND A ROUTE-

Rahul is fond of travelling and he visits cities and towns in the country whenever possible. All cities in the country are not connected to each other. Given the details of the cities that are connected to each city, source city from where he begins the travel and the destination city of the travel, design an algorithm and write a C++ code to list down the cities in the travel. Rahul must not visit a city more than once. When the destination city name is in the connected cities of the current city, chose it and complete the route. When the destination city name is not in the list of connected cities to current city and there are more than one city from the current city, he sorts the city names and include the first minimum city name that is not yet visited. For example, if the connection between the cities are given as follows, source city as A and destination city as F the list of cities in the travel are A, B, D and F.

City
Connected Cities
A
E, B
B
D
C
E,D
D
F
E
F

Use vectors, maps and algorithms such as sort, find in STL for implementation. Assume that the connection of cities is very simple and there is a path as described in the problem.
Input Format
Number of cities that are connected to other cities, 'n'
Name of city1
Number of neighbouring cities for city1, 'm'
First neighbouring city of city1
Second neighbouring city of city1
...
mth neighbouring city of city1
...
Name of cityn
Number of neighbouring cities for cityn, 'm'
First neighbouring city of cityn
Second neighbouring city of cityn
...
mth neighbouring city of cityn

Output Format
Name of cities in the list

#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<map>
#include<algorithm>
class travel
{
    int num_Of_Cities;
    map<string,vector<string> > city_Connection;
    string source;
    string destn;
    vector<string> route;
    public:
    //In this function form the map that depicts the
    // the connection of cities,key is the name of the
    // city and value is a vector of cities that are
    // connected to the city
    void get();
    void find_Route();
    void print_Route();
};


ANSWER-





void travel::get()
{
    int t,i=0,j;
    vector<string> s;
    cin>>num_Of_Cities;
    for(; i<num_Of_Cities; i++)
    {
        cin>>source>>t;
        s.clear();
        for(j=0; j<t; j++)
        {
            cin>>destn;
            s.push_back(destn);
        }
        sort(s.begin(),s.end());
        cout<<endl;
        city_Connection[source]=s;
    }
    cin>>source>>destn;
    route.push_back(source);
}
void travel::find_Route()
    {
    vector<string> s;
    int j, k;
    while(source!=destn){
        j=0;
        s=city_Connection[source];
        for(k=0; k<route.size(); k++)
        if(route[k]==s[j])
        {
            j++;
            k=0;
        }
        for(k=0; k<s.size(); k++)
        if(destn==s[k])
        j=k;
        route.push_back(s[j]);
        source=s[j];
    }
}
void travel::print_Route()
{
for(int i=0; i<route.size(); i++)
cout<<route[i]<<endl;

}


PREWRITTEN-

int main()
{
travel t;
t.get();
t.find_Route();
t.print_Route();

}




QUESTION-

Jobs are submitted to an operating system. Operating system does something called job scheduling when a number of jobs are submitted to an operating system at the same time. Some of the jobs have only job id and time required to complete the job. Whereas some other jobs are having priority in addition to job id and time required. Given a set of jobs without priority print the id of the job that requires minimum time to execute and given a set of jobs with priority, print the id and priority of the job which requires minimum time to execute. Design a OOP model to solve the problem.
Input Format
Number of jobs without priority
Id of job1
Time required by job1
...
Id of job-n
Time required by job-n
Number of jobs with priority
Id of job1
Time required by job1
Priority of job1
...
Id of job-n
Time required by job-n
Priority of job-n
Output Format
Id of job with out priority that requires minimum time
Id of job with priority that requires minimum time  and its priority.

#include<iostream>
#include<iomanip>
#include<string.h>
using namespace std;
class job
{
    int id;
    float time;
    public:
    void get();
    //function to return time
    float gettime();
    int getid();
};
class job_Sch
{
int num;
job j[20];
public:
//function to print job with maximum time
void find_Max();
void get();
};


ANSWER-


bool pri=false;
int p[20];
void job :: get()
{
    cin>>id>>time;
}
float job :: gettime()
{
    return(time);
}
int job :: getid()
{
    return(id);
}
void job_Sch :: get()
{
    cin>>num;
    for(int i=0;i<num;i++)
    {
        j[i].get();
        if(pri)
        cin>>p[i];
    }
}
void job_Sch :: find_Max()
{
    int max=-1,pos;
    for(int i=0;i<num;i++)
    if(max<j[i].gettime())
    {
        pos=i;
        max=j[i].gettime();
    }
    cout<<j[pos].getid()<<"\n";
    if(pri)
    cout<<p[pos]<<"\n";
}
int main()
{
    job_Sch j;
    j.get();
    j.find_Max();
    pri=true;
    j.get();
    j.find_Max();
    return(0);
}




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. For example, if the details in the following table is given

Room Number of Guest
Name of Guest
Room number the guest who arrived next
125
John
210
157
Kannan
125
210
Kumar
-1
315
Anand
157

If Jegan has room number as 315, room number of the friend who arrived first, then the output should be
Anand 315
Kannan 157
John 125
Kumar 210
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.
Input Format
Number of friends
Room number of guest1
Name of guest1
Room number the guest who arrived next to guest1
Room number of guest2
Name of guest2
Room number the guest who arrived next to guest2
....
Room number of guestn
Name of guestn
-1 ( Last guest doesn't posses any room number)
Room number that Jegan has
Output Format
Name of guest1 and his Room number separated by tab
Name of guest2 and his Room number separated by tab
...
Name of guestn and his Room number separated by t



#include<iostream>
using namespace std;
#include<string>
#include<map>
struct guest
{
    int room_No;
    string name;
    int friend_Room_No;
    public:
    void get();
};
class hotel
{
    int num_Of_Guest;
    map<int,guest> stay_Det;
    //this room number is with jegan
    int first_Room_No;
    public:
    void get();
    //this function should print
    //details such as name and room number
    // of guest to serve coffee
    void serve_Coffee();
};

ANSWER-


void guest :: get()
{
    cin>>name>>friend_Room_No;
}
void hotel :: get()
{
    int val;
    guest g;
    cin>>num_Of_Guest;
    for(int i=0;i<num_Of_Guest;i++)
    {
        cin>>val;
        g.get();
        stay_Det.insert(pair <int,guest> (val,g));
    }
    cin>>first_Room_No;
}
void hotel :: serve_Coffee()
{
    int rm=first_Room_No;
    while(rm!=-1)
    {
        cout<<stay_Det[rm].name<<" "<<rm<<"\n";
        rm=stay_Det[rm].friend_Room_No;
    }
}



PREWRITTEN-

main()
{
hotel h;
h.get();
h.serve_Coffee();

}


Q-Given a set of names, design an algorithm and write a C++ code to form a sorted list, in the descending order of names that do  begin with a vowel.
Hint: Use STL for implementation
Input Format:
Number of names, 'n'
Name 1
Name 2

Name n
Output Format:

Names that do  begin with a vowel in a descending  order.

ANS-
int main()
{
    int num;
    string name;
    vector <string> names;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        cin>>name;
        names.push_back(name);
    }
    sort(names.begin(),names.end());
    for(vector <string> :: iterator i=names.end();i!=names.begin();i--)
    {
        name=*(i-1);
        if(name[0]=='A' || name[0]=='E' || name[0]=='I' || name[0]=='O' || name[0]=='U')
        cout<<name<<"\n";
    }
    return(0);

}


Q-3-D points- multiply and increment

Given a point in three-dimensional space with x-coordinate, y-coordinate, z-coordinates,  Provide a function increment with one, two and three parameters to transform  the values of all the three coordinates. When the function with one parameter is called increment all the three , by same value .  When the function with two arguments is called multiply each coordinates by the sum  of the two parameters. when the function with three arguments is called, increment x-coordinate  by the value of first parameter, y-coordinate by the value of the second parameter and z-coordinate  by the value of the third parameter.
Input format:
Enter the coordinates of the point
X-coordinate
Y-coordinate
Z-coordinate
Enter the increment value for function with one parameter
Enter the values for the function with two parameters
Enter the  increment values for function with three parameters
Output format:
Display the coordinates of the point after calling function with one parameter
Display the coordinates of the point after calling function with two parameters

Display the coordinates of the point after calling function with three parameters

C++ code-


#include<iostream>

using namespace std;

class dim

{

    int x,y,z;

    public :

    void get()
    {
        cin>>x>>y>>z;
    }
   void increment(int val)
    {
        x+=val;
        y+=val;
        z+=val;
    }
    void increment(int val1,int val2)
    {        
x*=val1+val2;
        y*=val1+val2;
        z*=val1+val2;
    }
    void increment(int val1,int val2,int val3)
    {
        x+=val1;
        y+=val2;
        z+=val3;
    }
    void print()
    {
        cout<<x<<"\n"<<y<<"\n"<<z<<"\n";
    }
};

prewritten-

int main()
{
dim d1;
d1.get();
int inc;
cin>>inc;
int p1,p2;
cin>>p1>>p2;
int ix,iy,iz;
cin>>ix>>iy>>iz;
d1.increment(inc);
d1.print();
d1.increment(p1,p2);
d1.print();
d1.increment(ix,iy,iz);
d1.print();
}


PSeudocode-

start
step1-derive a class dim
step2-make functions get() which takes input of x,y,z.
step3-make another function increment which increment the values and returns them and a similar one using pointers.
step4-make another function called as print which prints the value of x,y,z.
stop.


Processing-

void increment(int val1,int val2)
    {        
x*=val1+val2;
        y*=val1+val2;
        z*=val1+val2;
    }
    void increment(int val1,int val2,int val3)
    {
        x+=val1;
        y+=val2;
        z+=val3;
    }

Wednesday, 26 April 2017

INLAB 10

INLAB-10 (tested-100% working)


A workshop has a variety of cars. The details of the car such as car number, miles driven, and gallons of gas used in each car, are stored in a file.
Car Number          Miles Driven              Gallons used
54                           250                        19
62                           525                        38
71                          123                          6
85                         1,322                        86
97                          235                         14
Write a  C++ program that reads the data in the file created and displays the car number, miles driven, gallons used, and the miles per gallon (mileage)  for each car.

Input Format:
Name of the file
Contents of the input file.
car number, miles driven and gallons (separated by a tab)  of car1 in line1
car number, miles driven and gallons (separated by a tab) of car2 in line2
….
car number, miles driven and gallons (separated by a tab) of car-n in line-n

Output Format:
car number, miles driven, gallons and mileage of car1 (separated by tab)
car number, miles driven, gallons and mileage of car2 (separated by tab)

car number, miles driven, gallons and mileage of car-n (separated by tab)
Total miles driven (by all the cars)
Total gallons used (by all the cars)
average miles per gallon for all the cars




SOLUTION-

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{
    char name[20];
    cin>>name;
    ifstream fin;
    fin.open(name,ios::in);
    int no,n;
    float m,g=0,tm=0,tg=0,avg=0;
    for(int i=0;i<5;i++)
    {
        fin>>no>>m>>g;
        tm=tm+m;
        tg=tg+g;
        avg=avg+(m/g);
        cout<<no<<"\t";
        cout<<fixed<<setprecision(2)<<m<<"\t"<<g<<"\t"<<m/g<<"\n";
    }
    cout<<tm<<"\n"<<tg<<"\n"<<avg<<"\n"<<avg/5;
    fin.close();
    return(0);

}

Sunday, 23 April 2017

PPS7

PPS7

Q1-ARRANGE ITEMS FOR SOLAR VEHICLE

There are ‘n’ bags in a corner of a city and they have to be moved to the centre of the city by a solar vehicle. The vehicle starts shunting from morning, the vehicle can carry more load in the mornings than in the evening when sunlight would be dimmer. Given the details of items in the bag, sort the bag in descending so that the vehicle can safely carry it to the centre of the city. Use vector and map in STL. Also use the sort algorithm defined in STL.
Hint: Use total weight of bag as key and object of bag as value, insert total weight of each bag into a vector. Use STL sort algorithm to sort it and print the details of bag in order
Input Format
Number of bags ‘n’
Name of bag1
Number of types of items in bag1, ‘t’
Weight of item1 in bag1
Number of item1 in bag1
Weight of item2 in bag1
Number of item2 in bag1
Weight of itemt in bag1
Number of itemt in bag1
….
….
Name of bagn
Number of types of items in bagn, ‘t’
Weight of item1 in bagn
Number of item1 in bagn
Weight of item2 in bagn
Number of item2 in bagn
Weight of itemt in bagn
Number of itemt in bagn
Output Format
Print name of bags in sorted order.
Sorting must be done in descending order based on the weight of the bag
Solution
#include
#include
 #include
#include
using namespace std;
class bag
{
char name[30];
int num_Of_Items;
float item_Wt[20];
float item_Count[20];
public:
void get();
//print only name of bag
void print();
//Compute weight from details given
float compute();
};
bool wayToSort(int i, int j);
class solar
{
map<float,bag> m1;
vector v;
int num_Bags;
public:
//get details of bags and insert into map and vector
// In map, key – weight and value – details of bag
// In vector, weight of bags
void get();
void sort_Vec();
//print name of bags in sorted order
void print_In_Order();
};

START


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 w=0;
    for(int i=0; i<num_Of_Items; i++)
    w+=item_Wt[i]*item_Count[i];
}
void solar::get(){
    bag t;
    cin>>num_Bags;
    for(int i=0; i<num_Bags; i++){
        t.get();
        v.push_back(t.compute());
        m1[v[i]]=t;
    }
}
bool wayToSort(int i, int j){
    return i>j;
}
void solar::sort_Vec(){
    sort(v.begin(),v.end(),wayToSort);
}
void solar::print_In_Order(){
    for(int i=0; i<num_Bags; i++)
   m1.at(v[i]).print();
}

END



int main()
{
solar s;
s.get();
s.sort_Vec();
s.print_In_Order();
}


Q2-vector of characters

Design a class char Vector that has a character vector as datamember. Provide member functions in the class to create Vector, duplicate Vector, duplicate Rev Vector 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.
Input Format
String to be stored in vector1
String to be stored in vector2

Output Format
Print duplicate Vector of vector1
Print duplicate RevVector of vector2

ANS-

#include <iostream>
#include <vector>
#include <string>
using namespace std;
class charVector
{
    vector<char> cv;
    public:
    //Function to initialize vector by characters in a string
    void initializeVector(string);
    //Function to duplicate a vector at its back
    void dupVector();
    //Function to add reverse of a vector at its back
    void dupRevVector();
    void print();
};

START

void charVector::initializeVector(string s)
{
    int i=0, l=s.length();
    for(;i<l; i++)
    cv.push_back(s[i]);
}
void charVector::dupVector(){
    int i=0, l=cv.size();
    for(;i<l; i++)
    cv.push_back(cv[i]);
}
void charVector::dupRevVector(){
    int i, l=cv.size();
    for(i=l-1;i>=0; i--)
    cv.push_back(cv[i]);
}
void charVector::print(){
    for(vector<char>::iterator i=cv.begin(); i!=cv.end(); i++)
    cout<<*i;
}




END

int main()
{
    charVector ch1,ch2;
    string s1,s2;
    cin>>s1>>s2;
    ch1.initializeVector(s1);
    ch2.initializeVector(s2);  
    ch1.dupVector();
    ch2.dupRevVector();
    ch1.print();
    cout<<endl;
    ch2.print();
    cout<<endl;

}







Generic Double Ended Queue
Design a generic class queue to maintain a list of elements. Queueis a linear data structure that follow FIFO ordering of elements. It is a special kind of list where elements can be inserted at one end and deleted at the end. There are two end points called front and rear. Front is the point of deletion and that move for each deletion but always points to the element that was inserted first among the elements remaining in the queue. Rear is the point of the insertion and move for each insertion but always points to the element that was inserted last among the elements remaining in the queue. Provide member functions to check if a queue is empty, queue is full, enqueue and dequeue.
Enqueue - if queue is not full, increment rear and place the element
dequeue – If queue is not empty, return element pointed by front and increment front
isempty – Return true when front is greater than rear or when both are -1
isfull – return true when rear is capacity - 1
Extended the class queue to create another generic class deque which represents a double ended queue. In deque, elements can be added to or removed from either the front or rear. The operations in a deque are defined as follows
push_back – Insert an element at the rear (enqeue in Queue)
push_front – Insert an element at the front, if queue is not full push all elements forward and place new element, change rear also
pop_back – Remove an element at the rear, if queue is not empty,return element pointed by rear and decrement rear
pop_front – Remove an element at the front (dequeue in Queue)
print - print elements of queue from first to last
Input Format
Choice of queue and data type (1 – integer linear queue, 2 – Stringdeque)
Choice of operation
For queue – 1 – isempty, 2 – isfull, 3 – enqueue, 4 – dequeue, 5 –Print content of queue, 6 - exit
for enqueue option 3, element to be inserted will follow the choice
For deque – 1 – isempty, 2 – isfull, 3 – push_back, 4 – push_front, 5 – pop_back, 6 – pop_front 7 – Print content of deque, 8 - exit
for both the push options 3 and 4, element to be inserted will follow the choice


#include<iostream>
using namespace std;
#include<string>
//global error flag for dequeue
bool ERR_Flag = false;
template<class T>
class queue
{
    protected:
    int front;
    int rear;
    int capacity;
    T *ele;
    public:
    //constructor to allocate memory and initialize data members
    queue();
    bool isempty();
    bool isfull();
    //Check if queue is full before insertion
    //if queue is full return false
    // insert element and return true otherwise
    bool enqueue(T data);
    //funtion to remove an element and return
    T dequeue();
    ~queue();
    void print();
};
template<class T>
class deque:public queue<T>
{
    public:
    bool push_Back(T data);
    bool push_Front(T data);
    T pop_Front();
    T pop_Back();
};

start


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

end


int main()
{
    int d_Choice;
    int op_Choice;
    deque<string> d;
    queue<int> q;
    cin>>d_Choice;   
    if(d_Choice==1)
    {
        while(1)
        {
            cin>>op_Choice;
            if(op_Choice==1)
            {
                if(q.isempty())
                cout<<"Queue is empty"<<endl;
                else
                cout<<"Queue is not empty"<<endl;
            }
            else if(op_Choice==2)
            {
                if(q.isfull())
                cout<<"Queue is full"<<endl;
                else
                cout<<"Queue is not full"<<endl;
            }
            else if(op_Choice==3)
            {
                int data;
                cin>>data;
                if(!q.enqueue(data))
                cout<<"Queue full insertion not possible";
            }
            else if(op_Choice==4)
            {
                q.dequeue();
                if(ERR_Flag)
                cout<<"Queue is empty";
            }
            else if(op_Choice==5)
            {
                q.print();
            }
            else if(op_Choice==6)
            {
            break;
            }
        }
    }
    else if(d_Choice==2)
    {
        string s_Data;
        while(1)
        {
            cin>>op_Choice;
            if(op_Choice==1)
            {
                if(d.isempty())
                cout<<"Queue is empty"<<endl;
                else
                cout<<"Queue is not empty"<<endl;
            }
            else if(op_Choice==2)
            {
                if(d.isfull())
                cout<<"Queue is full"<<endl;
                else
                cout<<"Queue is not full"<<endl;
            }
            else if(op_Choice==3)
            {
                cin>>s_Data;
                if(!d.push_Back(s_Data))
                cout<<"Queue full insertion not possible";
            }
            else if(op_Choice==4)
            {
                cin>>s_Data;
                if(!d.push_Front(s_Data))
                cout<<"Queue full insertion not possible";               
                 
            }
            else if(op_Choice==5)
            {
                d.pop_Back();
                if(ERR_Flag)
                cout<<"Queue is empty";
            }
            else if(op_Choice==6)
            {
                d.pop_Front();
                if(ERR_Flag)
                cout<<"Queue is empty";
            }
            else if(op_Choice==7)
            {
                d.print();             
            }
            else if(op_Choice==8)
            {
                break;
            }
        }
    }
}

Q4-List of even points

Design a class point with datamembers: name of the point(string), value of the x-coordinate and the value of  y-coordinate. Here, value of the x-coordinate and the value of the y-coordinate should be an even integer. Provide functions to get the details of a point, print the details of a point and a function to compute the  squared distance between the point and a given point(passed to the function as an argument). Design a class mobileSpace, with a list of points(both the coordinates must be even integers) that represent the position of the mobile towers and a point that  represents the  position of mobile phone. With the position of the mobile towers and mobile phone given as input,   provide member functions to get the details and determine the tower  with which the mobile phone can be connected based on the `longest squared distance between the phone and the tower’ Use STL for implementation.
Input Format
Number of towers, ‘n’
Name of tower1
X-coordinate  of tower1
Y-coordinate of tower1
Name of tower-n
X-coordinate of tower-n
Y-coordinate  of tower-n
Name of mobile
X-coordinate  of mobile phone
Y-coordinate  of mobile phone
Output Format
Name of the tower to which the phone has to be connected
Solution

#include<iostream>
using namespace std;
class point
{
char name[30];
int x;
int y;
public:
void get();
void print();
int dist(point p);
};
class mobile
{
int num_Tower_Pts;
list tower_Pts;
point mobile_Pt;
public:
void get();
point find_Max();
};

start


void point::get(){
    cin>>name>>x>>y;
}
void point::print(){
    cout<<name<<endl;
}
int point::dist(point p){
    if(x%2!=0 || y%2!=0 || p.x%2!=0 || p.y%2!=0){
        cout<<"Invalid input";
        exit(0);
    }
    else
    return pow(p.x-x,2)+pow(p.y-y,2);
}
void mobile::get(){
    point t;
    cin>>num_Tower_Pts;
    for(int i=0; i<num_Tower_Pts; i++){
        t.get();
        tower_Pts.push_back(t);
    }
    mobile_Pt.get();
}
point mobile::find_Max(){
    list<point>::iterator i=tower_Pts.begin();
    int d=(*i).dist(mobile_Pt), n=1, p=0;
    i++;
    for(;i!=tower_Pts.end(); i++, n++)
    if(d<(*i).dist(mobile_Pt)){
        d=(*i).dist(mobile_Pt);
        p=n;
    }
    i=tower_Pts.begin();
    advance(i,p);
    return *i;
}

end

int main()
{
mobile m;
m.get();
(m.find_Max()).print();
}

Q5Symmertic 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.
Hint: To create a matrix with 'r' rows and 'c' columns
vector<vector<int> > m1(r,vector<int>(c,0));
Input Format
Dimension of matrix, 'n'
Element in row1 col1
Element in row1 col2
...
Element in row1 coln
Element in row2 col1
Element in row2 col2
...
Element in row2 coln
...
...
Element in rown col1
Element in rown col2
...
Element in rown coln
Output Format
Print Symmetric or Not symmetric

#include<iostream>
#include<vector>
using namespace std;
main()
{
int n, i=0, j, f=0;
cin>>n;
vector<vector<int> >m(n,vector<int>(n));
for(;i<n; i++)
for(j=0; j<n; j++)
cin>>m[i][j];
for(i=0; i<n; i++)
for(j=0; j<n; j++)
if(m[i][j]!=m[j][i])
{
f++;
break;
}
if(f)
 cout<<"Not symmetric";
else
cout<<"Symmetric";

}



GPT4ALL - A new LLaMa (Large Language Model)

posted 29th March, 2023 - 11:50, GPT4ALL launched 1 hr ago  What if we use AI generated prompt and response to train another AI - Exactly th...