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

Java Program to Print an Integer (Entered by the User)

 

Java Program to Print an Integer (Entered by the User)

import java.util.Scanner;

class Int{

public static void main(String args[])

{

int num; 

System.out.println("Enter value is:");  

Scanner obj=new Scanner(System.in);

num=obj.nextInt();

System.out.println("Eneterd value is:"+num);   

}

}

Software Devlopmnet Engineers off-Campus Internship

Software Devlopmnet Engineers off-Campus Internship

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


C language and C++ progaming