Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

CS304 Assignment No 2 (Last Date Dec 10)

Problem Statement:

Keeping in view the above class diagram, you have to write code for the below mentioned classes and show their relationship with each other:

 

1. Class Bus:

Attribute:

BusNo:string

SeatingCapacity:int

SeatsReservedSofar:int

 

Methods/Operations/Getters/Setters:

GetSeatingCapacity():int

SetSeatingCapacity(bCap:int)

GetBusNo():string

SetBusNo(bNo:string)

ReserveSeat(p:Passenger)

DisplayInfo()

 

2. Class passenger:

 

Attribute:

Name:string

Gender:char

 

Methods/Operations/Getters/Setters:

SetPassengerName(name:string)

GetPassengerName():string

SetGender(gender:char)

GetGender():char

 

Hint: You have to implement the relationship of aggregation between class “bus” and “passenger” through C++ code.

  • Your program should allow the user to enter information of bus while creating and information of passenger while adding a passenger in bus.
  • It should give option (yes/no) to add more passenger if capacity of bus allows.
  • After adding the last passenger (i.e. when adding a passenger makes buss full) or “No” is selected as option, it should display the complete summary about bus and all passenger in bus as shown in output below. 

 

Output:

Views: 12549

Attachments:

Replies to This Discussion


#include<iostream>
using namespace std;
# include <stdlib.h>

class Passenger
{
char* Name;
char* Gend;

public:

Passenger()
{
Name = new char[200];
Gend = new char[10];
}

void SetPassengerName(char* c)
{
Name = c;
}

char* GetPassengerName()
{
return Name;
}

void SetGender(char* d)
{
Gend= d;
}

char* GetGender()
{
return Gen;
}
};

class Bus
{
char* busNo;
int seatingCapacity;
int seatsReservedSofar;
Passenger *passenger;

public:

Bus()
{
busNo = new char[50];
seatingCapacity = seatsReservedSofar = 0;
}

int GetSeatingCapacity()
{
return seatingCapacity;
}

void SetSeatingCapacity(int sc)
{
seatingCapacity = sc;
}

char* GetBusNo()
{
return busNo;
}

void SetBusNo(char* b)
{
busNo = b;
}

int GetSeatsReserved()
{
return seatsReservedSofar;
}

void SetSeatsReserved(int s)
{
seatsReservedSofar += s;
}

void ReserveSeat(Passenger *p)
{
passenger = p;
}

void DisplayInfo()
{
cout "\nBus Information\n";
cout "Bus no. : " busNo endl;
cout "Bus max capacity:" seatingCapacity endl;
cout "Total passenger in bus now : " seatsReservedSofar;
cout endl endl;
cout "Passenger information\n";
cout "Passenger Name : " passenger->GetPassengerName();
cout endl;
cout "Gender : " passenger->GetGender();
cout endlendl;
cout"...........................................................";
coutendl;
}
};

int main()
{
int maxCapacity = 0;
char* registrationNumber=new char[50];

cout "\nCreating a new bus....\n\n";
cout "Enter max capacity of bus for passengers : ";
cin >> maxCapacity;

cout "Enter the bus registration number : ";
cin >> registrationNumber;

Bus bus;

bus.SetBusNo(registrationNumber);
bus.SetSeatingCapacity(maxCapacity);

cout ".... Bus is created successfully\n\n";

char* PNs = new char[50];
char Gend;
int S = 0;
char C = 'n';

do
{

cout "Enter the passenger name: ";
cin >> PNs;

cout "Enter the passenger gender (m for male and f for female) : ";
cin >> Gend;

cout "Seats reserved for passenger : ";
cin >> S;

Passenger* p = new Passenger();

if (Gend == 'mm')
{
p->SetGender("male");
}
else if (Gend == 'f')
{
p->SetGender("Femail");
}

p->SetPassengerName(PNs);
bus.SetSeatsReserved(S);
bus.ReserveSeat(p);

cout "Remaining Capacity : " bus.GetSeatingCapacity() - bus.GetSeatsReserved() endl endl;

if (bus.GetSeatsReserved() != bus.GetSeatingCapacity())
{
cout "Do you want to add more passenger (y/Y for yes and another character for no)? : ";
cin >> C;
}

} while (C == 'y' || C == 'Y');

bus.DisplayInfo();

system("pause");
return 0;
}

capcity negitave

very good  Abbas khan....

thanks  + M.Tariq Malik bro/..........

but meri tu ho gei compile bi aur error bi ni ha koi is mein >>>>>

main ny bar bar check ki hai :,(

In sub me se koi b thk ni hai + M.Tariq Malik !

Sub run ho jaatay hain but thk ni hain according to given condition in our problem

#include
#include
#include
using namespace std;

// Passenger class
class Passenger
{
private:
// name and gender declaration
char* name;
char* gender;

// Public method
public:

Passenger()
{
// Creating new arrays
name = new char[100];
gender = new char[6];
}
// Setter Functions
void SetPassengerName(char* n)
{
name = n;
}

void SetGender(char* g)
{
gender = g;
}
// Getter Functions
char* GetPassengerName()
{
return name;
}

char* GetGender()
{
return gender;
}
};
// Bus Class
class Bus
{

private:
char* busNo;
int seatingCapacity;
int seatsReservedSoFar;
Passenger *passenger;

public:

Bus()
{
busNo = new char[100];
seatingCapacity = seatsReservedSoFar = 0;
}

// Getter Functions
int GetSeatingCapacity()
{
return seatingCapacity;
}

char* GetBusNo()
{
return busNo;
}

int GetSeatsReserved()
{
return seatsReservedSoFar;
}

// Setter Functions
void SetSeatingCapacity(int cap)
{
seatingCapacity = cap;
}

void SetBusNo(char* b)
{
busNo = b;
}

void SetSeatsReserved(int s)
{
seatsReservedSoFar += s;
}

void ReserveSeat(Passenger *p)
{
passenger = p;
}
// void function to display Bus Information
void DisplayInfo()
{
cout "\n\nBus Information\n";
cout "Bus no. : " busNo endl;
cout "Bus max capacity : " seatingCapacity endl;
cout "Total passenger in bus now : " seatsReservedSoFar endl endl endl;
cout "Passenger information\n";
cout "Passenger Name : " passenger->GetPassengerName() endl;
cout "Gender : " passenger->GetGender() endl endl;
}
};


// main function
int main()
{
int maxCapacity = 0;
char* registrationNumber=new char[100];

cout "Creating a new bus....\n\n";
cout "Enter max capacity of bus for passengers : ";
cin >> maxCapacity;

cout "\n" "Enter the bus registration number : ";
cin >> registrationNumber;

Bus bus;

bus.SetBusNo(registrationNumber);
bus.SetSeatingCapacity(maxCapacity);

cout ".... Bus is created successfully\n\n\n";

char* passName = new char[100];
char gender;
int seats = 0;
char choice = 'n';

do
{

cout "Enter the passenger name: ";
cin >> passName;

cout "Enter the passenger gender (m for male and f for female) : ";
cin >> gender;

cout "Seats reserved for passenger : ";
cin >> seats;

Passenger* p = new Passenger();

if (gender == 'm')
{
p->SetGender("male");
}
else if (gender == 'f')
{
p->SetGender("Female");
}

p->SetPassengerName(passName);
bus.SetSeatsReserved(seats);
bus.ReserveSeat(p);

cout "Remaining Capacity : " bus.GetSeatingCapacity() - bus.GetSeatsReserved() endl endl;

if (bus.GetSeatsReserved() != bus.GetSeatingCapacity())
{
cout "Do you want to add more passenger (y/Y for yes and another character for no)? : ";
cin >> choice;
}

} while (choice == 'y' || choice == 'Y');

bus.DisplayInfo();

system("pause");
return 0;
}

Anyone plz upload the correct assignment . . . . .

CS304_2 

Attachments:

#include
using namespace std;
# include

class Passenger
{
char* Name;
char* Gen;

public:

Passenger()
{
Name = new char[200];
Gen = new char[10];
}

void SetPassengerName(char* c)
{
Name = c;
}

char* GetPassengerName()
{
return Name;
}

void SetGender(char* d)
{
Gens = d;
}

char* GetGender()
{
return Gen;
}
};

class Bus
{
char* busNo;
int seatingCapacity;
int seatsReservedSofar;
Passenger *passenger;

public:

Bus()
{
busNo = new char[50];
seatingCapacity = seatsReservedSofar = 0;
}

int GetSeatingCapacity()
{
return seatingCapacity;
}

void SetSeatingCapacity(int sc)
{
seatingCapacity = sc;
}

char* GetBusNo()
{
return busNo;
}

void SetBusNo(char* b)
{
busNo = b;
}

int GetSeatsReserved()
{
return seatsReservedSofar;
}

void SetSeatsReserved(int s)
{
seatsReservedSofar += s;
}

void ReserveSeat(Passenger *p)
{
passenger = p;
}

void DisplayInfo()
{
cout "\nBus Information\n"; cout "Bus no. : " busNo endl; cout "Bus max capacity:" seatingCapacity endl; cout "Total passenger in bus now : " seatsReservedSofar; cout endl endl; cout "Passenger information\n"; cout "Passenger Name : " passenger->GetPassengerName();
cout endl; cout "Gender : " passenger->GetGender();
cout endl<"...........................................................";="" coutendl;="" }="" };="" int="" main()="" {="" maxcapacity="0;" char*="" registrationnumber="new" char[50];="" cout="" ="" "\ncreating="" a="" new="" bus....\n\n";="" "enter="" max="" capacity="" of="" bus="" for="" passengers="" :="" ";="" cin="">> maxCapacity;

cout "Enter the bus registration number : "; cin >> registrationNumber;

Bus bus;

bus.SetBusNo(registrationNumber);
bus.SetSeatingCapacity(maxCapacity);

cout ".... Bus is created successfully\n\n"; char* PNs = new char[50]; char Gend; int S = 0; char C = 'n'; do { cout "Enter the passenger name: "; cin >> PNs;

cout "Enter the passenger gender (m for male and f for female) : "; cin >> Gen;

cout "Seats reserved for passenger : "; cin >> S;

Passenger* p = new Passenger();

if (Gen == 'mail')
{
p->SetGender("male");
}
else if (Gen == 'f')
{
p->SetGender("Female");
}

p->SetPassengerName(PN);
bus.SetSeatsReserved(S);
bus.ReserveSeat(p);

cout "Remaining Capacity : " bus.GetSeatingCapacity() - bus.GetSeatsReserved() endl endl; if (bus.GetSeatsReserved() != bus.GetSeatingCapacity()) { cout "Do you want to add more passenger (y/Y for yes and another character for no)? : "; cin >> C;
}

} while (C == 'y' || C == 'Y');

bus.DisplayInfo();

system("pause");
return 0;
}

Working code of Cs304 Assignment
#include<iostream>
using namespace std;

class Passenger
{
char* name;
char* gender;

public:

Passenger()
{
name = new char[50];
gender = new char[10];
}

void SetPassengerName(char* a)
{
name = a;
}

char* GetPassengerName()
{
return name;
}

void SetGender(char* b)
{
gender = b;
}

char* GetGender()
{
return gender;
}
};

class Bus
{
char* busNo;
int seatingCapacity;
int seatsReservedSoFar;
Passenger *passenger;

public:

Bus()
{
busNo = new char[50];
seatingCapacity = seatsReservedSoFar = 0;
}

int GetSeatingCapacity()
{
return seatingCapacity;
}

void SetSeatingCapacity(int cap)
{
seatingCapacity = cap;
}

char* GetBusNo()
{
return busNo;
}

void SetBusNo(char* c)
{
busNo = c;
}

int GetSeatsReserved()
{
return seatsReservedSoFar;
}

void SetSeatsReserved(int s)
{
seatsReservedSoFar += s;
}

void ReserveSeat(Passenger *p)
{
passenger = p;
}

void DisplayInfo()
{
cout "\n\nBus Information\n";
cout "Bus no. : " busNo endl;
cout "Bus max capacity : " seatingCapacity endl;
cout "Total passenger in bus now : " seatsReservedSoFar endl endl endl;
cout "Passenger information\n";
cout "Passenger Name : " passenger->GetPassengerName() endl;
cout "Gender : " passenger->GetGender() endl endl;
}
};



int main()
{
int maxCapacity = 0;
char* registrationNumber=new char[50];

cout "Creating a new bus....\n\n\n";
cout "Enter max capacity of bus for passengers : ";
cin >> maxCapacity;

cout "Enter the bus registration number : ";
cin >> registrationNumber;

Bus bus;

bus.SetBusNo(registrationNumber);
bus.SetSeatingCapacity(maxCapacity);

cout ".... Bus is created successfully\n\n\n";

char* passName = new char[50];
char gender;
int seats = 0;
char choice = 'n';

do
{

cout "Enter the passenger name: ";
cin >> passName;

cout "Enter the passenger gender (m for male and f for female) : ";
cin >> gender;

cout "Seats reserved for passenger : ";
cin >> seats;

Passenger* p = new Passenger();

if (gender == 'm')
{
p->SetGender("male");
}
else if (gender == 'f')
{
p->SetGender("Female");
}

p->SetPassengerName(passName);
bus.SetSeatsReserved(seats);
bus.ReserveSeat(p);

cout "Remaining Capacity : " bus.GetSeatingCapacity() - bus.GetSeatsReserved() endl endl;

if (bus.GetSeatsReserved() != bus.GetSeatingCapacity())
{
cout "Do you want to add more passenger (y/Y for yes and another character for no)? : ";
cin >> choice;
}

} while (choice == 'y' || choice == 'Y');

bus.DisplayInfo();

system("pause");
return 0;
}

RSS

© 2022   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service