0% found this document useful (0 votes)
18 views

Lab 1

The document is a lab report for CS212: Object Oriented Programming, detailing various tasks involving C++ arrays and structures. It includes tasks for creating one-dimensional and two-dimensional arrays to store student information, as well as a project simulating a real estate platform with functionalities for property listings. The report outlines the code and expected outputs for each task, demonstrating the application of object-oriented programming concepts.

Uploaded by

ayyaniqbalmirza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lab 1

The document is a lab report for CS212: Object Oriented Programming, detailing various tasks involving C++ arrays and structures. It includes tasks for creating one-dimensional and two-dimensional arrays to store student information, as well as a project simulating a real estate platform with functionalities for property listings. The report outlines the code and expected outputs for each task, demonstrating the application of object-oriented programming concepts.

Uploaded by

ayyaniqbalmirza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CS212: Object Oriented Programming

Class: BEE-15D
Fall 2023
Lab 1: Fundamentals of C++ arrays
Date: 19th September 2024

Faculty Member: Miss Ayesha.


Muhammad Farhan Tariq 480608
Muhammad Ayyan Iqbal 465330

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 1


Contents
LAB TASK 1: ...............................................................................................................................2
Task 1 output: ..........................................................................................................................3
Task 1 Code: ...........................................................................................................................4
LAB TASK 2: ...............................................................................................................................5
PART 1: ...................................................................................................................................5
TASK 2 OUTPUT 1: .................................................................................................................5
TASK 2 CODE 1: .....................................................................................................................6
PART 2: ...................................................................................................................................7
TASK 2 OUTPUT 2: .................................................................................................................7
TASK 2 CODE 2: .....................................................................................................................8
LAB TASK 3: ...............................................................................................................................9
TASK 3 CASE 1 OUTPUT: ....................................................................................................10
TASK 3 CASE 2 OUTPUT: .................................................................................................... 11
TASK 3 CODE: .....................................................................................................................12

LAB TASK 1:
Create the following three one-dimensional arrays: Name, Age,
Grade - Allow the user to input the name, grade, and age of 5
students. - Find your name in the `name` array and then retrieve
LAB REPORT: OBJECT-ORIENTED PROGRAMMING 2
your age and grade from the respective index.

Task 1 output:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 3


Task 1 Code:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 4


LAB TASK 2:
PART 1:
Repeat `Task 1` using a 2-dimensional array.
TASK 2 OUTPUT 1:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 5


TASK 2 CODE 1:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 6


PART 2:
Repeat `Task 1` using a structure.
TASK 2 OUTPUT 2:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 7


TASK 2 CODE 2:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 8


LAB TASK 3:
“Redfin” is a technology-powered real estate brokerage that offers
services for buying, selling, and renting homes, combining
innovative tools with local real estate agents to provide a more
efficient home search and selling experience. You’re tasked with
creating a system that simulates a simplified version of a real
estate platform like “Redfin”. This platform stores property listings
and allows users to perform the following operations.
Add Property Listings: Users will input the details of a property
(address, price, number of rooms, square footage), and the
system will store them in an array or list of properties. – Filter
Listings by Price: Users should be able to view properties that fall
within a certain price range, such as between $600,000 and
$900,000. – Sort Listings by Square Footage: Users should be
able to sort the properties by square footage, so they can see the
smallest or largest properties first. – Calculate Price per Square
Foot: For each property, the system should calculate the price per
square foot, giving users an idea of how much space they're
getting for the price.

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 9


TASK 3 CASE 1 OUTPUT:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 10


TASK 3 CASE 2 OUTPUT:

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 11


TASK 3 CODE:
#include<iostream>

using namespace std;

int main(){

// Creating structure for property info

struct Info{

int ID;

string street;

string city;

string state;

long long zipcode;

int bedrooms;

float bathrooms;

int squareFootage;

long long price;

double pricepersqft;

};

int NUMOFPROPERTIES = 5;

// Creating an array of objects

Info property[NUMOFPROPERTIES];

// Initializing the array of objects with property details

property[0] = {1, "123 Main St", "Los Angles", "CA", 90001, 3, 2.5, 1500, 750000};

property[1] = {2, "456 Oak Ave", "San Francisco", "CA", 94102, 4, 3.0, 2000, 12000000};

property[2] = {3, "789 Pine Dr", "Seattle", "WA", 98101, 2, 1.5, 1200, 650000};

property[3] = {4, "101 Maple Blvd", "Portland", "OR", 97201, 3, 2.0, 1800, 800000};

property[4] = {5, "202 Birch Ln", "Austin", "TX", 73301, 4, 3.5, 2500, 950000};

// Code for calculating price per square foot of each property

for(int i = 0; i < NUMOFPROPERTIES; i++){

property[i].pricepersqft = ((property[i].price) / property[i].squareFootage);

int option;

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 12


cout << "Which operation do you wish to perform? " << endl;

cout << "Press 1 if you wish to view properties within a specified range. " << endl;

cout << "Press 2 if you wish to view all properties in order of increasing area." << endl;

cin >> option;

switch(option) {

// Case 1 View properties within a specified price range

case 1: {

long long lowerLim, upperLim;

cout << "Enter lower limit and upper limit of your price range (separated by space):" << endl;

cin >> lowerLim >> upperLim;

cout << "Your options are: " << endl;

for(int i = 0; i < NUMOFPROPERTIES; i++){

if(property[i].price >= lowerLim && property[i].price <= upperLim) {

cout << "Property no. " << i + 1 << endl;

cout << " ID: " << property[i].ID << endl;

cout << " Street: " << property[i].street << endl;

cout << " City: " << property[i].city << endl;

cout << " State: " << property[i].state << endl;

cout << " ZipCode: " << property[i].zipcode << endl;

cout << " No. of bedrooms: " << property[i].bedrooms << endl;

cout << " No. of bathrooms: " << property[i].bathrooms << endl;

cout << " Square footage: " << property[i].squareFootage << " sq ft" << endl;

cout << " Price: $" << property[i].price << endl;

cout << " Price per square foot: $" << property[i].pricepersqft << endl;

cout << "----------------------------" << endl;

break;

// Case 2 Sort and view properties by square footage

case 2: {

// Selection sort algorithm to sort the properties by by square footage

for(int i = 0; i < NUMOFPROPERTIES - 1; i++){

int minIndex = i;

for(int k = i + 1; k < NUMOFPROPERTIES; k++) {

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 13


if(property[k].squareFootage < property[minIndex].squareFootage)

minIndex = k;

if(minIndex != i) {

Info temp = property[i];

property[i] = property[minIndex];

property[minIndex] = temp;

// Printing sorted properties

cout << "Properties sorted by increasing area (square footage):" << endl;

for(int i = 0; i < NUMOFPROPERTIES; i++) {

cout << "Property ID: " << property[i].ID << endl;

cout << " Street: " << property[i].street << endl;

cout << " City: " << property[i].city << endl;

cout << " State: " << property[i].state << endl;

cout << " ZipCode: " << property[i].zipcode << endl;

cout << " Bedrooms: " << property[i].bedrooms << endl;

cout << " Bathrooms: " << property[i].bathrooms << endl;

cout << " Square Footage: " << property[i].squareFootage << " sq ft" << endl;

cout << " Price: $" << property[i].price << endl;

cout << " Price per square foot: $" << property[i].pricepersqft << endl;

cout << "----------------------------" << endl;

break;

default:

cout << "Invalid option selected." << endl;

return 0;

LAB REPORT: OBJECT-ORIENTED PROGRAMMING 14

You might also like