0% found this document useful (0 votes)
28 views7 pages

MST Solution With Markingscheme 23 Oct 2024

Uploaded by

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

MST Solution With Markingscheme 23 Oct 2024

Uploaded by

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

Thapar Institute ofEngineering and Technology, Patiala, Punjab

Department of Computer Science and Engineering


MST Solution (Dated: 05-10-2024)

Course (Code): Object Oriented Programming (UTA018)


QN Solution [Evaluation Parameter: Required construct and Syntax] Marks
#include <iostream> No Marks
using namespace std;
class Triangle { 1 mark
private:
double base; Irrespective of datatype
double height; and punctuation.
public:
Triangle(double b, double h) 1 mark
{
base=b;
height=h;
}
double getArea() { 0.5 marks
return (0.5 * base * height);
}
1(a) static Triangle& compareArea(Triangle &t1, Triangle &t2) { 0.5 marks
return (t1.getArea() > t2.getArea()) ? t1 : t2;
}
void display() { No marks
cout << "Base: " << base << ", Height: " << height << ", Area: " <<
getArea() << endl;
} };
int main() { No marks
Triangle t1(3.0, 4.0); // Area = 6.0
Triangle t2(5.0, 6.0); // Area = 15.0

Triangle &largerTriangle= Triangle::compareArea(t1, t2);

cout << "The triangle with the larger area is: " << endl;
largerTriangle.display();

return 0;
}
QN Solution [Evaluation Parameter: Syntax and logic] Marks
#include<iostream> 1 mark
using namespace std;
namespace items
{
int count=20;
}
1(b) namespace customers 1 mark
{
int count=12;
}
using namespace items;
int main()
{
cout<<count; }
QN Solution [Evaluation Parameter: Syntax] Marks
2(a) #include <iostream> No marks
using namespace std;
class Car { 1 mark
private:
int speed; Irrespective of
double fuel; datatype and
punctuation.
public: 1 mark
Car(int speed, double fuel) {
this->speed = speed;
this->fuel = fuel;
}
void displayDetails() { 1 mark
cout << "Car Speed: " << speed << " km/h" << endl;
cout << "Car Fuel: " << fuel << " liters" << endl;
}};
int main() { No mark
// Create a car object with speed 120 km/h and fuel 50 liters
Car myCar(120, 50.0);

// Display car details


myCar.displayDetails();

return 0;
}
2(b) Data Abstraction: Data abstraction is an OOP concept that focuses on 1 mark
exposing only the essential details of an object while hiding the complex
or irrelevant internal workings. This helps in simplifying the interaction
with the object, allowing users to work with it without needing to
understand the implementation details.

Example: Think of a TV remote control. When you press the "power"


button, the TV turns on or off, but you don’t need to know how the
remote communicates with the TV, or how the internal circuitry works.
All you need to understand is the functionality of pressing the button.
In programming, this would be similar to providing public methods to
interact with an object, while keeping the data and complex operations
hidden.

Purpose: It reduces complexity by hiding unnecessary details.


Implementation: Through public methods (functions) that provide access
to certain behaviors of an object, while keeping data members private.
Polymorphism: Polymorphism allows one function or method to behave 1 mark
differently based on the object that calls it. It helps objects of different
types to respond to the same method in their own way.
QN Solution [Evaluation Parameter: Required Construct and Syntax] Marks
3 int main() { 2 mark
int n;
cout << "Enter the number of shopping carts: ";
cin >> n;

// Dynamically allocate memory for 'n' pointers to ShoppingCart


objects
ShoppingCart** carts = new ShoppingCart*[n];
// Input and initialize each shopping cart dynamically 2 mark
for (int i = 0; i < n; ++i) {
int id, count;
string name;
cout << "\nEnter details for Cart " << (i + 1) << ":\n";
cout << "Cart ID: ";
cin >> id;
cin.ignore(); // Clear newline from buffer
cout << "Customer Name: ";
getline(cin, name);
cout << "Number of Items: ";
cin >> count;

// Dynamically allocate each ShoppingCart object using the


constructor
carts[i] = new ShoppingCart(id, name, count);
}
// Display details of each shopping cart 1 mark
cout << "\nShopping Cart Details:\n";
for (int i = 0; i < n; ++i) {
carts[i]->display_cart();
cout << endl;
}

// Deallocate memory for each ShoppingCart object


for (int i = 0; i < n; ++i) {
delete carts[i]; // Delete each object
}

// Deallocate memory for the array of pointers


delete[] carts;

return 0;
}
QN Solution [Evaluation Parameter: Required Construct and Logic] Marks
4 #include <iostream> 1 mark
#include <string>
using namespace std;
class Recipient;
class Donor { 1 mark
private:
string donor_name;
double balance;
public:
void set_details(string name, double amount) {
donor_name = name;
balance = amount;
}
void display() {
cout << "Donor Name: " << donor_name << endl;
cout << "Donor Balance: $" << balance << endl;
}
double get_balance() {
return balance;
}
friend void transfer(Donor &donor, Recipient &recipient, double amount);
};

class Recipient { 1 mark


private:
string recipient_name;
double account_balance;
double amount_required;

public:
void set_details(string name, double balance, double amount) {
recipient_name = name;
account_balance = balance;
amount_required = amount;
}

void display() {
cout << "Recipient Name: " << recipient_name << endl;
cout << "Recipient Balance: $" << account_balance << endl;
cout << "Amount Needed: $" << amount_required << endl;
}
double get_balance() const {
return account_balance;
}
friend void transfer(Donor &donor, Recipient &recipient, double amount);
};
void transfer(Donor &donor, Recipient &recipient, double amount) { 1 mark
if (donor.get_balance() >= amount) {
donor.balance -= amount; // Deduct from donor's balance
recipient.account_balance += amount; // Add to recipient's balance
cout<< " completed successfully!" << endl;
} else {
cout << "Insufficient funds for the transfer!" << endl; } }
int main() { 1 mark
Donor donor;
Recipient recipient;
donor.set_details("Alice", 500); // Donor Alice has $500
recipient.set_details("Bob", 100, 200); // Recipient Bob has $100 and needs
$200

cout << "Initial Donor and Recipient Details:" << endl;


donor.display();
recipient.display();

transfer(donor, recipient, 150); // Trying to transfer $150

cout << "\nDonor and Recipient Details After Transfer:" << endl;
donor.display();
recipient.display();

return 0;
}

QN Solution [Evaluation Parameter: Required Construct and Syntax] Marks


5 #include<iostream> 1 mark
using namespace std;
class Number{int a,b,c,d;
public:
Number( int x=0, int y=0, int z=100, int w=30) 2 mark
{ a=x; b=y; c=z; d=w;
}
(If student hasn’t made the above default parameterised constructor, then
Default Constructor 1M + Parameterised Constructor 1M)

Number( Number &n) 1 mark


{ a=n.a; b=n.b; c=n.c; d=n.d;
}
void showdata() 1 mark
{ cout<<a<<" "<<b<<" "<<c<<" "<<d<<" ";
}
};
int main()
{ Number n1;
Number n2(10,20);
Number n3(30, 40, 50, 60);
Number n4(n2);
Number n5=n1;
n1.showdata();
n2.showdata();
n3.showdata();
n4.showdata();
n5.showdata();
return 0;
}
QN Solution [Evaluation Parameter: Required Construct and Syntax] Marks
6 #include <iostream>
#include <string>
using namespace std;
class Company {
protected:
string company_name;
string location;
public:
Company(string cname, string loc)
{
company_name=cname;
location=loc;
}
void displayCompany() {
cout << "Company Name: " << company_name << endl;
cout << "Location: " << location << endl;
}
};
class Team : public Company {
protected:
string team_name;
string project;
public:
Team(string cname, string loc, string tname, string proj): Company(cname,
loc)
{
team_name=tname;
project=proj;
}
void displayTeam() {
cout << "Team Name: " << team_name << endl;
cout << "Project: " << project << endl;
}
};
class Developer : public Team {
private:
string developer_name;
string programming_language;
public:
Developer(string cname, string loc, string tname, string proj, string dname,
string lang)
: Team(cname, loc, tname, proj)
{
developer_name=dname;
programming_language=lang;
}
void displayDeveloper() {
displayCompany(); // Call base class display function
displayTeam(); // Call intermediate class display function
cout << "Developer Name: " << developer_name << endl;
cout << "Programming Language: " << programming_language << endl;
}
};
int main() {

Developer obj("Tech Solutions", "New York", "AI Team", "AI Chatbot",


"Alice", "C++");
obj.displayDeveloper();
return 0;
}

Marking scheme of Q6
1 mark for base class constructor
1 mark for intermediate class constructor
1 mark for derived class constructor
1 mark for display function
1 mark for main

List of Evaluators
S.N. Question No. Evaluator
1 Q1 Dr. Suresh Raikwar
2 Q2 All here
3 Q3 Dr. Palika Chopra (coordinator)
4 Q4 Dr. Lokendra Vishwakarma
5 Q5 Dr. Seemu Sharma
6 Q6 Dr. Nidhi Kalra (coordinator)

Thanks

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