Follow us on Facebook

Header Ads

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Welcome to JAVA POint

Hotel Management System Project in C++

 


Hotel Management System Project in C++

Given the data for Hotel management and User:
Hotel Data:
Hotel Name     Room Available     Location     Rating      Price per Room
H1                4               Bangalore      5           100
H2                5               Bangalore      5           200
H3                6               Mumbai         3           100
User Data:
User Name         UserID             Booking Cost
U1                 2                  1000
U2                 3                  1200
U3                 4                  1100
The task is to answer the following question.
Print the hotel data.
Sort hotels by Name.
Sort Hotel by highest rating.
Print Hotel data for Bangalore Location.
Sort hotels by maximum number of rooms Available.
Print user Booking data.
Machine coding round involves solving a design problem in a matter of a couple of hours.
It requires designing and coding a clean, modular and extensible solution based on a specific set of requirements.
Approach:
Create classes for Hotel data and User data.
Initialize variables that stores Hotel data and User data.
Create Objects for Hotel and user classes that access the Hotel data and User data.
initialize two vector array that holds the hotel data and and user data.
solve the Above questions one by one.
Below is the implementation of the above approach

Solution C++

// C++ program to solve the given question
 
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// Create class for hotel data.

class Hotel {
public:
    string name;
    int roomAvl;
    string location;
    int rating;
    int pricePr;
};
// Create class for user data.
class User : public Hotel {
public:
    string uname;
    int uId;
    int cost;
};  
// Function to Sort Hotels by
// Bangalore location

bool sortByBan(Hotel& A, Hotel& B)
{
    return A.name > B.name;
}
// Function to sort hotels by rating.
bool sortByr(Hotel& A, Hotel& B)
{
    return A.rating > B.rating;
}
// Function to sort hotels
// by rooms availability.

bool sortByRoomAvalable(Hotel& A,Hotel& B)              
{
    return A.roomAvl < B.roomAvl;
}
// Print hotels data.

void PrintHotelData(vector<Hotel> hotels)
{
    cout << "PRINT HOTELS DATA:" << endl;
    cout << "HotelName"  << " " << "Room Avalable"<< "  " << "Location"
         << "Rating"  << "    " << "PricePer Room:" << endl;
           for (int i = 0; i < 3; i++) {
           cout << hotels[i].name << "   "<< hotels[i].roomAvl  << " "<< hotels[i].location << "  "<<         hotels[i].rating   << "    "<< hotels[i].pricePr   << endl;
            
    }
    cout << endl;
}
// Sort Hotels data by name.
void SortHotelByName(vector<Hotel> hotels)
{
    cout << "SORT BY NAME:" << endl;
 
    std::sort(hotels.begin(), hotels.end(),
              sortByBan);
 
    for (int i = 0; i < hotels.size(); i++) {
        cout << hotels[i].name << " "
             << hotels[i].roomAvl << " "
             << hotels[i].location << " "
             << hotels[i].rating << " "
             << " " << hotels[i].pricePr
             << endl;
    }
    cout << endl;
}
// Sort Hotels by rating
void SortHotelByRating(vector<Hotel> hotels)
{
    cout << "SORT BY A RATING:" << endl;
    std::sort(hotels.begin(),
              hotels.end(), sortByr);  
    for (int i = 0; i < hotels.size(); i++) {
        cout << hotels[i].name << " "
             << hotels[i].roomAvl << " "
             << hotels[i].location << " "
             << hotels[i].rating << " "
             << " " << hotels[i].pricePr
             << endl;
    }
    cout << endl;
}
// Print Hotels for any city Location.
void PrintHotelBycity(string s,
                      vector<Hotel> hotels)
{
    cout << "HOTELS FOR " << s
         << " LOCATION IS:"
         << endl;
          for (int i = 0; i < hotels.size(); i++) {
        if (hotels[i].location == s) {
            cout << hotels[i].name << " "
                 << hotels[i].roomAvl << " "
                 << hotels[i].location << " "
                 << hotels[i].rating << " "
                 << " " << hotels[i].pricePr
                 << endl;
        }
    }
    cout << endl;
}
// Sort hotels by room Available.
void SortByRoomAvailable(vector<Hotel> hotels)
{
    cout << "SORT BY ROOM AVAILABLE:" << endl;
    std::sort(hotels.begin(), hotels.end(),
              sortByRoomAvalable);
    for (int i = hotels.size() - 1; i >= 0; i--) {
        cout << hotels[i].name << " "
             << hotels[i].roomAvl << " "
             << hotels[i].location << " "
             << hotels[i].rating << " "
             << " " << hotels[i].pricePr
             << endl;
    }
    cout << endl;
}
// Print the user's data
void PrintUserData(string userName[],
                   int userId[],
                   int bookingCost[],
                   vector<Hotel> hotels)
            {
    vector<User> user;
    User u;
    // Access user data.
    for (int i = 0; i < 3; i++) {
        u.uname = userName[i];
        u.uId = userId[i];
        u.cost = bookingCost[i];
        user.push_back(u);
    }
    // Print User data.
    cout << "PRINT USER BOOKING DATA:"<< endl;   
    cout << "UserName" << " " << "UserID" << " "  << "HotelName"<< " "
         << "BookingCost" << endl;     for (int i = 0; i < user.size(); i++) {
        cout << user[i].uname   << " " << user[i].uId   << "  "<< hotels[i].name  << "   "<< user[i].cost
            << user[i].cost << endl;                        
    }
}
// Function  to solve
// Hotel Management problem
void HotelManagement(string userName[],
                     int userId[],
                     string hotelName[],
                     int bookingCost[],
                     int rooms[],
                     string locations[],
                     int ratings[],
                     int prices[])
{
    // Initialize arrays that stores
    // hotel data and user data
    vector<Hotel> hotels;
    // Create Objects for
    // hotel and user.
    Hotel h;
    // Initialise the data
    for (int i = 0; i < 3; i++)
 {
        h.name = hotelName[i];
        h.roomAvl = rooms[i];
        h.location = locations[i];
        h.rating = ratings[i];
        h.pricePr = prices[i];
        hotels.push_back(h);
    }
    cout << endl;
    // Call the various operations
    PrintHotelData(hotels);
    SortHotelByName(hotels);
    SortHotelByRating(hotels);
    PrintHotelBycity("Bangalore", hotels);
    SortByRoomAvailable(hotels);
    PrintUserData(userName,  userId,   bookingCost, hotels);                              
}
// Driver Code.
int main()
{
    // Initialize variables to stores
    // hotels data and user data.
    string userName[] = { "U1", "U2", "U3" };
    int userId[] = { 2, 3, 4 };
    string hotelName[] = { "H1", "H2", "H3" };
    int bookingCost[] = { 1000, 1200, 1100 };
    int rooms[] = { 4, 5, 6 };
    string locations[] = { "Bangalore",  "Bangalore",  "Mumbai" };
    int ratings[] = { 5, 5, 3 };
    int prices[] = { 100, 200, 100 };
    // Function to perform operation;
    HotelManagement(userName, userId, hotelName, bookingCost, rooms, locations, ratings, prices);
    return 0;
}
***Output***
***Print The Hotel Data***
HotelName   Room Avalable    Location    Rating    PricePer Room:
H1          4              Bangalore       5            100
H2          5              Bangalore       5            200
H3          6              Mumbai          3            100

SORT BY NAME:
H3 6 Mumbai 3  100
H2 5 Bangalore 5  200
H1 4 Bangalore 5  100

SORT BY A RATING:
H1 4 Bangalore 5  100
H2 5 Bangalore 5  200
H3 6 Mumbai 3  100

HOTELS FOR Bangalore LOCATION IS:
H1 4 Bangalore 5  100
H2 5 Bangalore 5  200

SORT BY ROOM AVAILABLE:
H3 6 Mumbai 3  100
H2 5 Bangalore 5  200
H1 4 Bangalore 5  100

PRINT USER BOOKING DATA:
UserName UserID HotelName BookingCost
U1         2        H1         1000
U2         3        H2         1200
U3         4        H3         1100

Write a program to find the Seven elements using Quick Sort in c(Data Structure and Algorithm).

                                                 DATA STRUCTURE AND ALGORITHM

Write a program to find the  Seven elements using Quick Sort in c(Data Structure and Algorithm).

 

#include<stdio.h>

void quick_sort(int a[10],int low,int high);

void main()

{

 int pivot,high,low,i,j,n,a[10];

printf("how many element you want to sort");

scanf("%d",&n);

printf("enter the element of an array");

for(i=0;i<n;i++)

{

scanf("%d",&a[i]);

}

quick_sort(a,0,n-1);

low=0;

high=n-1;

quick_sort(a,low,high);

printf("after sorting the element are");

for(i=0;i<n;i++)

printf("%d\t",a[i]);

}

void quick_sort(int a[10],int low,int high)

{

 int pivot,i,j,t;

if(low<high)

{

pivot=a[low];

i=low;

j=high;

while(i<j)

{

while(pivot>=a[i] && i<=high)

i++;

while(pivot<a[j] && j>=low)

j--;

if(i<j)

{

t=a[i];

a[i]=a[j];

a[j]=t;

}

}

a[low]=a[j];

a[j]=pivot;

quick_sort(a,low,j-1);

quick_sort(a,j+1,high);

}

}

                       OUTPUT

amr@amr-virtual-machine:~$ gcc Quick.c

amr@amr-virtual-machine:~$ ./a.out

how many element you want to sort8

enter the element of an array9

7

4

5

1

6

8

4

after sorting the element are1  4    4    5    6    7    8


Write a C Program to find the Adjacency List in C (Data Structure )

                     DATA STRUCTURE AND ALGORITHM  

Write a C Program to find the Adjacency List in C (Data Structure )

struct node //If you  have plzz write the Header file

{

int vertex;

struct node *next;

}*v[10];

void create(int m[20][20],int n)

{

int i,j;

char ans;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

{

printf("is there an edge between %d and %d",i+1,j+1);

scanf("%d",&m[i][j]);

}

}

void disp(int m[20][20],int n)

{

int i,j;

printf("\nthe adjancy matrix is:\n");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

printf("%d",m[i][j]);

printf("\n");

}

}

void create1(int m[20][20],int n)

{

int i,j;

struct node *temp,*newnode;

for(i=0;i<n;i++)

{

v[i]=NULL;

for(j=0;j<n;j++)

{

if(m[i][j]==1)

{

newnode=(struct node *)malloc(sizeof(struct node));

newnode->next=NULL;

newnode->vertex=j+1;

if(v[i]==NULL)

v[i]=temp=newnode;

else

{

temp->next=newnode;

temp=newnode;

}

}

}

}

}

void displist(int n)

{

struct node *temp;

int i;

for(i=0;i<n;i++)

{

printf("\n v %d |",i+1);

temp=v[i];

while(temp)

{

 

printf("v %d->",temp->vertex);

temp=temp->next;

}

printf("NULL");

}

}

void main()

{

int m[20][20],n;

printf("\n enter no of vertex");

scanf("%d",&n);

create(m,n);

disp(m,n);

create1(m,n);

displist(n);

}

_______________________________________________________________________                           OUTPUT

 

ame@amr-virtual-machine:~$ ./graph

 

enter no of vertex3

is there an edge between 1 and 10

is there an edge between 1 and 21

is there an edge between 1 and 30

is there an edge between 2 and 11

is there an edge between 2 and 20

is there an edge between 2 and 31

is there an edge between 3 and 10

is there an edge between 3 and 20

is there an edge between 3 and 30

 

the adjancy matrix is:

010

101

000

 

 v 1 |v 2->NULL

 v 2 |v 1->v 3->NULL

 v 3 |NULL


SERVLET IN JAVA

                                  *********SERVLET IN JAVA*************

-          Servlet technology is used to create a web application (resides at server side and                         generates a dynamic web page).

-          What is a Servlet?

-          Servlet is a technology which is used to create a web application.

-          Servlet is an API that provides many interfaces and classes including                                 documentation.

-          Servlet is an interface that must be implemented for creating any Servlet.

-          Servlet is a class that extends the capabilities of the servers and responds to the               incoming requests. It can respond to any requests.

        Servlet is a web component that is deployed on the server to create a dynamic web page.

Methods of GenericServlet Class:                                                          

  • public void init(ServletConfig)
  • public abstract void service(ServletRequest request,ServletResponse response)
  • public void destroy()
  • public ServletConfig getServletConfig()
  • public String getServletInfo()
  • Public String getInitParameterNames()

HTTPServlet  Class:

-          It is also an abstract class.

-          This class gives implementation of various service() methods of Servlet interface.

-          To create a servlet,we should create a class that extends HTTPServlet class.

-          The servlet class must not override service().

-          It will override only doGet() and doPost().

The service() method listens to Http methods (GET,POST) from request stream and invokes doGet() and doPost() methods based on Http method type




It extend 

2.Handling HTTPResponse:

-          Servlet API provides two important interfaces ServletResponse and HttpServletREsponse to assist in sending response to client.

-          The HttpServletResponse interface enables a servlet to formulate an HTTP response to a client.javax.servlet.HttpServlet

-          Have in-built HTTP protocol support and are

more  useful in a Sun Java System web server.

-          For both servlet types,you implement the

constructor init() and the destructor destroy() to initialize or deallocate resources.

-          All  servlet must implement a service() method,which is responsible for handling servlet requests.

-          HTTP servlet provide a service method method  that automatically routes the request to another method .

-          Http  servlet override doGet() to process GET requests and doPost() to process POST request

-          HTTP servlet is HTTP protocol specific .


Life Cycle of a Servlet (Servlet Life Cycle):

       Servlet class is loaded

       Servlet instance is created

       init() method is invoked

       service() method is invoked

       destroy() method is invoked

       The web container maintains the life cycle of a servlet instance. Let's see the life cycle of the servlet:



Methods of servlets

 

1)      init() Method

public  void init(ServletConfig config) throws ServletException

-called only once.

-          It is called only when the servlet is created.

-          it is used for one-time initializations.

2) service() Method

public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { }

-is the main method to perform the actual task. The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client.

The doGet() and doPost() are most frequently used methods with in each service request.


a)doGet() Method

       A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet code }

b)doPost() Method

       A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet code}

3) destroy() Method

-          The destroy() method is called only once at the end of the life cycle of a servlet.

-          This method gives your servlet a chance to close database connections, halt background threads, write cookie lists or hit counts to disk, and perform other such cleanup activities.

       After the destroy() method is called, the servlet object is marked for garbage collection. The destroy method definition looks like this −

public void destroy() { // Finalization code... 


Simple servlet program:

HelloServlet.java

import java.io.*;

import  javax.servlet.*;

public class HelloServlet extends GenericServlet

{

                public void service(ServletRequest request,ServletErsponse response) throws ServletException,IOException

      {

                                response.setContentType(“text/html”);

                                PrintWriter pw= response.getWriter();

                                pw.println(“<B> Hello!”);

                                pw.close();

                }

}


Handling HTTPRequest and HTTPResponse

  1. Handling HTTPRequest:

-          When a browser requests for a web page, it sends lot of information  to the web server which cannot be read directly because this information travel as a part of header of HTTP request.

Methods

Descritption

String  getContextPath()

This  method returns the portion of the request URL that indicates the context of the request.

Cookies getCookies()

This method return an array containing all of the Cookie objects the client sent with this request.

String getQueryString()

Returns the query string that is contained in the request URL after the path.

HttpSession getSession()

Returns the current HttpSession associated with this request

String getMethod()

Returns the name of the HTTP method with which this request was made ,e.g. GET,POST,

Part getPart(String name)

Gets the Part with the given name.

String getPathInfo()

Returns any extra path information associated with URL the client sent when it made this request.

String getServletPath()

Returns the part of this requests URL that calls the servlet.

 2.Handling HTTPResponse:

-          Servlet API provides two important interfaces ServletResponse and HttpServletREsponse to assist in sending response to client.

-          The HttpServletResponse interface enables a servlet to formulate an HTTP response to a client.


Methods

Description

void addCookie(Cookie cookie)

Method adds the specified cookie to the response

void sendRedirect(String location)

Sends a temporary redirest response to the client using the specified redirect location URL and clears the buffer

int getStatus()

Gets the current status code of this response.

String getHeader(String name)

Gets the value of the response header with the given name.

void setHeader(String name,String value)

sets a response header with the given name and value.

void setStatus(int sc)

Sets the status code for this response.

void sendError(int sc,String msg)

Sends an error response to the client using the specified status and clears the buffer.

 



Software Devlopmnet Engineers off-Campus Internship

Software Devlopment Engineers  off-Campus Internship

DESCRIPTION

The SDE Intern experience is a unique at Amazon. You get to rub shoulders with outstanding software engineers and researchers with industry leading technical abilities, solving challenging engineering problems that affect millions of Amazon customers. You also get to collaborate and work with teams across the globe, in the process being exposed to a range of technologies, best practices and solution patterns. The Role: SDE Intern will be part of Device OS Organization and will be responsible for developing features for FireOS. Fire OS (based on Android) is used across a wide family of Amazon devices including Tablets, TV and exciting new array of products that are under development. This full time position requires candidates with good experience in C++/Java, Linux internals and preferably Android. In addition, the position will require very good analytical and problem solving skills. 
 


  BASIC QUALIFICATIONS:


Programming experience with at least one modern language such as Java, C++, or C# including object-oriented design · Self-driven, quick starters, passionate problem solvers with curious mind who love solving very complex, very challenging real world problems · Strong coding skills (e.g Java, C/C++ and/or other languages such as Python, Shell script, Ruby) · Solid fundamentals in Data Structure & Algorithm · Excited with opportunities to solve very complex problems and willingness to learn · Ability to think abstractly & deal with ambiguous problems · Willing to own all stages of development process: requirements, design, implementation, testing, and operational support · Ability to effectively articulate technical challenges and solutions · Excellent interpersonal communication with strong reading / written English skills. PREFERRED QUALIFICATIONS Major in Computer Science · Experience with UNIX/Linux environment · Have technical internship experience


. CLICK HERE TO APPLY: https://www.amazon.jobs/en/jobs/1090103/sde-intern


Join Telegram Channel Click Here Daily Jobs Update:Software Devlopmnet Engineers  off-Campus Internship

C language and C++ progaming