0% found this document useful (0 votes)
6 views4 pages

24F0525 Oop6

The document contains code for two object-oriented programming tasks in C++. The first task defines a 'vehicle' class with attributes like make, model, year, and mileage, along with methods to set and get these attributes. The second task introduces a 'LibraryBook' class that includes details about a book such as title, author, ISBN, year published, and availability, also providing methods for setting and displaying these details.

Uploaded by

najeli7982
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

24F0525 Oop6

The document contains code for two object-oriented programming tasks in C++. The first task defines a 'vehicle' class with attributes like make, model, year, and mileage, along with methods to set and get these attributes. The second task introduces a 'LibraryBook' class that includes details about a book such as title, author, ISBN, year published, and availability, also providing methods for setting and displaying these details.

Uploaded by

najeli7982
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Object Oriented Programming

LAB No: 6
Name: Muhammad Khalil

Section: BCS-2E

Roll No: 24F-0525

TASK : 2

Code:
#include <iostream>
#include <string>
using namespace std;

class vehicle
{
private:
string make;
string model;
int year;
double mileage;

public:

vehicle() { make = ""; model = ""; year = 0; mileage = 0.0;}

void set_make(string a) { make = a; }


void set_model(string b) { model = b; }
void set_year(int c) { year = c; }
void set_mileage(double d) { mileage = d; }

string get_make() { return make; }


string get_model() { return model; }
int get_year() { return year; }
double get_mileage() { return mileage; }

void display() {
cout << "Vehicle Details:" << endl;
cout << "Make: " << get_make() << endl;
cout << "Model: " << get_model() << endl;
cout << "Year: " << get_year() << endl;
cout << "Mileage: " << get_mileage() << " km" << endl;
}
};

int main() {
vehicle v1;
string make, model;
int year;
double mileage;

cout << "Enter Make: ";


getline(cin, make);
v1.set_make(make);

cout << "Enter Model: ";


getline(cin, model);
v1.set_model(model);

cout << "Enter Year: ";


cin >> year;
v1.set_year(year);

cout << "Enter Mileage: ";


cin >> mileage;
v1.set_mileage(mileage);

cin.ignore();

v1.display();

system("pause");
return 0;
}

Outpur:

TASK: 3
Code:
#include <iostream>
#include <string>
using namespace std;

class LibraryBook {
private:
string title;
string author;
string isbn;
int yearPublished;
bool available;

public:
LibraryBook() {
title = "";
author = "";
isbn = "";
yearPublished = 0;
available = true;
}

void set_title(string t) { title = t; }


void set_author(string a) { author = a; }
void set_isbn(string i) { isbn = i; }
void set_yearPublished(int y) { yearPublished = y; }
void set_available(bool av) { available = av; }

string get_title() { return title; }


string get_author() { return author; }
string get_isbn() { return isbn; }
int get_yearPublished() { return yearPublished; }
bool is_available() { return available; }

// Display Function
void display() {
cout << "\nBook Details:" << endl;
cout << "Title: " << get_title() << endl;
cout << "Author: " << get_author() << endl;
cout << "ISBN: " << get_isbn() << endl;
cout << "Year Published: " << get_yearPublished() << endl;
cout << "Available: " << (is_available() ? "Yes" : "No") << endl;
}
};

int main() {
LibraryBook book;
string title, author, isbn;
int year;
char avail;

cout << "Enter Book Title: ";


getline(cin, title);
book.set_title(title);

cout << "Enter Author Name: ";


getline(cin, author);
book.set_author(author);

cout << "Enter ISBN Number: ";


getline(cin, isbn);
book.set_isbn(isbn);

cout << "Enter Year Published: ";


cin >> year;
book.set_yearPublished(year);

cout << "Is the book available? (Y/N): ";


cin >> avail;
book.set_available(avail == 'Y' || avail == 'y');
cin.ignore();

book.display();

system("pause");
return 0;
}

Ouptut:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy