CSC-101L-Object Oriented Programming Assignment # 01
CSC-101L-Object Oriented Programming Assignment # 01
Assignment # 01
Marks Obtained
Course Instructor:
Dr. Naureen Shaukat
Question 01:
1|Page
Object Oriented Programming Assignment 01
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
// Array of 5 employees
Employee employees[5];
2|Page
Object Oriented Programming Assignment 01
return 0;
}
Result Output:
3|Page
Object Oriented Programming Assignment 01
Explanation:
In this program i uses nested structures to manage and display information about employees
and their residential addresses. The Address structure stores house number, street, and city,
while the Employee structure includes name, code, and an embedded Address. It declares an
array of five employees to store details for multiple individuals. Using a loop, the program
collects user input for employee details and stores them in the array. Finally, it displays each
employee's name, code, and complete address in a clear, structured format.
4|Page
Object Oriented Programming Assignment 01
Question 02:
Code:
#include <iostream>
#include <string>
using namespace std;
class Book {
private:
string title;
string author;
string ISBN;
bool isAvailable; // true for available, false for issued
public:
// Constructor to initialize book details
Book(string t = "", string a = "", string i = "")
: title(t), author(a), ISBN(i), isAvailable(true) {}
5|Page
Object Oriented Programming Assignment 01
6|Page
Object Oriented Programming Assignment 01
};
int main() {
const int numBooks = 4;
Book library[numBooks];
// Perform operations
cout << "\nIssuing the first book...\n";
library[0].issueBook();
7|Page
Object Oriented Programming Assignment 01
return 0;
}
Output:
8|Page
Object Oriented Programming Assignment 01
Question 03:
Code:
#include <iostream>
#include <string>
using namespace std;
class Book {
9|Page
Object Oriented Programming Assignment 01
private:
string title;
string author;
string ISBN;
int availabilityStatus; // 1 for available, 0 for issued
public:
// Constructor to initialize book details
Book(string t , string a , string i ) : title(t), author(a), ISBN(i), availabilityStatus(1)
{}
// Function to enter book details (not used in this version)
void enterDetails() {
cout << "Enter Title: ";
cin>>title;
cout << "Enter Author: ";
cin>>author;
cout << "Enter ISBN: ";
cin>>ISBN;
availabilityStatus = 1; // New books are available by default
}
// Function to display book details
void displayDetails() const {
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "ISBN: " << ISBN << endl;
cout << "Availability: " << (availabilityStatus == 1 ? "Available" : "Issued") <<
endl;
}
// Function to issue a book
void issueBook() {
if (availabilityStatus == 1) {
availabilityStatus = 0;
cout << "Book issued successfully." << endl;
} else {
10 | P a g e
Object Oriented Programming Assignment 01
11 | P a g e
Object Oriented Programming Assignment 01
Question 04:
Code:
#include <iostream>
12 | P a g e
Object Oriented Programming Assignment 01
class Number {
private:
int value; // Data item to compare
public:
// Constructor
Number(int val = 0) : value(val) {}
13 | P a g e
Object Oriented Programming Assignment 01
int main() {
// Creating instances of the Number class
Number num1(20), num2(50), num3(30);
if (num1 == num3) {
cout << "num1 is equal to num3." << endl;
} else {
cout << "num1 is not equal to num3." << endl;
}
14 | P a g e
Object Oriented Programming Assignment 01
return 0;
}
Output:
Question 05:
Code:
##include <iostream>
#include <string>
using namespace std;
// Base Class
class Faculty {
protected:
string name;
string department;
int employeeID;
public:
// Constructor
Faculty(string n, string d, int id) : name(n), department(d), employeeID(id) {}
15 | P a g e
Object Oriented Programming Assignment 01
16 | P a g e
Object Oriented Programming Assignment 01
17 | P a g e
Object Oriented Programming Assignment 01
projectName(proj) {}
void displayInfo() override {
cout << "Lab Engineer Information:" << endl;
Faculty::displayInfo();
cout << "Current Project: " << projectName << endl;
}
};
int main() {
// Creating instances of different faculty members
Professor prof("Dr. Ryan", "Computer Science", 20202, 775000);
AssociateProfessor assocProf("Dr Ramzan Shahid", "Mathematics", 10342, 10);
AssistantProfessor assistProf("Ms Naureen ", "EE", 1003, 76);
Lecturer lec("MS.Faiqa ", "Mathematics", 1004, 3);
LabEngineer labEng("Dawood Khan", "CS", 1005, "Supercomputing");
// Displaying information of each faculty member
cout << endl;
prof.displayInfo();
cout << endl;
assocProf.displayInfo();
cout << endl;
assistProf.displayInfo();
cout << endl;
lec.displayInfo();
cout << endl;
labEng.displayInfo();
cout << endl;
return 0;
}
Output:
18 | P a g e
Object Oriented Programming Assignment 01
19 | P a g e
Object Oriented Programming Assignment 01
20 | P a g e