Aditya MP Oop
Aditya MP Oop
Aditya MP Oop
In the Subject of
“OBJECT ORIENTED PROGRAMMING USING C++”
AFFILIATED TO
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION , MUMBAI
SUBMITTED BY
GUIDED BY
Ms. Tanuja Bhoir
ACADEMIC YEAR
2024-2025
MAHARASHTRA STATE BOARD OF
TECHNICAL EDUCATION,
MUMBAI CERTIFICATE
I under signed hereby declare that the micro project report entitled
"Implementation Of Inheritance". I further declare that contents of this
report are properly citied and well acknowledge. This present report is not
submitted to any other examination of this or any other institute for the
award of any diploma.
We extend our special thanks to all teaching and non-teaching staff. Success is
nourished under the combination of perfect guidance, care and blessing.
Acknowledgement is the best way to convey Last few years spend in estimated
institution has moulded us into confident and aspiring engineers. We express our
sense of gratitude towards our project guide Ms. Tanuja Bhoir. It is because of her
valuable guidance, analytical approach encouragement that we could learn, work and
complete the project. We will always cherish great experience work under the
enthusiastic guidance.
We are also grateful to our principal and our vice principal who not only supported us
in our project but also encouraged for every creative activity. We also sincerely give
thanks to our head of department Mrs. Madhura Mahindrakar of computer and its
sector, friends and well-wishers to directly or indirectly contribute for the success of
our maiden mission.
INDEX
1. INTRODUCTION 1
2. METHODOLOGY 2
4. CODE 3
5. OUTPUT 4
6. CONCLUSION 5
7. FUTURE SCOPE 6
INTRODUCTUCTION
OOP : Implementation of Constructor introduction
In object-oriented programming (OOP), a **constructor** is a special method invoked during
the creation of an object. It initializes the object’s attributes and prepares it for use.
Constructors share the same name as the class and do not have a return type, not even `void`
There are two main types of constructors:
**Default Constructor**: No parameters; initializes attributes with default values.
**Parameterized Constructor**: Accepts parameters to set specific initial values for attributes
Constructors can also facilitate techniques like constructor chaining and dependency injection,
enhancing code modularity and reusability
How does constructor chaining improve code readability
Constructor chaining enhances code readability by promoting **code reuse** and **reducing
duplication**. When multiple constructors are present, chaining allows one constructor to call
another, centralizing initialization logic in a single location. This minimizes repetitive code,
making it easier to maintain and understand.
Additionally, constructor chaining can clarify the relationships between different constructors,
as it clearly shows how they relate to one another. This structured approach leads to cleaner and
more organized code, ultimately improving overall readability and maintainability of the
program
What are some common pitfalls when using constructor chaining
Common pitfalls when using constructor chaining include:
**Complexity**: Managing multiple constructors can be cumbersome, especially if they have
similar tasks or parameters, leading to confusion about which constructor to use
**Circular Chains**: Improper chaining can create circular dependencies where constructors
call each other indefinitely, resulting in a `StackOverflowError`
**Error Handling**: Exceptions thrown during construction can leave objects in an
inconsistent state, complicating error recovery
**Parameter Order**: Constructors requiring parameters in a specific order can reduce
flexibility and lead to errors if not documentes
Awareness of these pitfalls can help developers implement constructor chaining effectively.
1
METHODOLOGY
Here’s a detailed methodology for developing a Storage Management System in C++ using object-
oriented programming principles:
Requirements Analysis
Identify user roles (e.g., admin, regular user).
Gather functional requirements:
Add an item.
Remove an item.
Update item details.
View inventory.
Search for an item.
System Design
Class Identification: Identify the core classes needed:
Item: Represents individual items in storage.
Storage: Manages a collection of items.
InventoryManager: Provides methods to perform operations on the storage.
User: Represents users interacting with the system.
cpp
#include <iostream>
#include <string>
#include <unordered_map>
class Item {
public:
Item(int id, const std::string& name, int quantity)
: item_id(id), item_name(name), item_quantity(quantity) {}
private:
int item_id;
std::string item_name;
int item_quantity;
};
class Storage {
public:
void addItem(const Item& item) {
items[item.getId()] = item;
}
private:
std::unordered_map<int, Item> items;
};
class InventoryManager {
public:
InventoryManager(Storage& storage) : storage(storage) {}
void checkInventory() {
storage.displayItems();
}
private:
Storage& storage;
};
```
Implementation
Create a `main` function to drive the application:
cpp
int main() {
Storage storage;
InventoryManager manager(storage);
// Example operations
storage.addItem(Item(1, "Widget", 10));
storage.addItem(Item(2, "Gadget", 5));
storage.removeItem(1);
std::cout << "\nInventory after removing Widget:\n";
manager.checkInventory();
return 0;
}
cpp
#include <cstdlib> // for exit()
int main() {
Storage storage;
InventoryManager manager(storage);
std::string command;
while (true) {
std::cout << "\nEnter command (add, remove, check, exit): ";
std::cin >> command;
if (command == "add") {
int id, quantity;
std::string name;
std::cout << "Enter ID, Name, Quantity: ";
std::cin >> id >> name >> quantity;
storage.addItem(Item(id, name, quantity));
} else if (command == "remove") {
int id;
std::cout << "Enter ID to remove: ";
std::cin >> id;
storage.removeItem(id);
} else if (command == "check") {
manager.checkInventory();
} else if (command == "exit") {
exit(0);
} else {
std::cout << "Invalid command.\n";
}
}
return 0;
}
Testing
Test each functionality individually to ensure correctness.
Consider edge cases, such as removing an item that doesn't exist or adding an item with an
existing ID.
Documentation
Document the codebase, explaining class responsibilities, methods, and usage.
Create a user manual outlining how to compile and run the program.
Deployment
Compile the project and ensure it runs smoothly on the target platform.
Share the code with stakeholders or deploy it for users.
Conclusion
This methodology provides a comprehensive guide for developing a Storage Management System in
C++. It emphasizes clarity in design and implementation while ensuring robust functionality. Focus
on testing and documentation to enhance usability and maintainability. Good luck with your project!
2
CODE
#include<iostream.h>
#include<conio.h>
const int m=20; class
dept
{
int amount[m],pris[m],k,a,b,amount1; int
code,code1,cod[m],s,last; public: float
price,price1; dept(void); void sell(void);
void total_items(void); void add_old(void);
void add_new(void); void show(void);
};
dept:: dept(void)
{ s=0;a=10;b=40;last=5;amount[0]=0;
for(int k=0;k<last;k++) { s=s+1;b=b+10;
cod[k]=s; amount[k]=a; pris[k]=b;
}
}
void dept::add_old(void)
{ cout<<"\nEnter item code:";
cin>>code1; cout<<"\nEnter item
price:"; cin>>price1;
for(k=0;k<last;k++)
{ if(code1==cod[k])
{ a=a+1; amount[k]=a;
pris[k]=price1;
}
// else
//cout<<"\nSorry..This item is not available.\n";
}
}
void dept::add_new(void) { cout<<"\
nEnter item code:"; cin>>code1; cout<<"\
nEnter amount of that item:";
cin>>amount1; cout<<"\nEnter item
price:"; cin>>price1;
cod[last]=code1;
amount[last]=amount1;
pris[last]=price1; last++;
}
void dept::show(void)
{ for(k=0;k<last;k++)
{
cout<<"\nCODE:"<<cod[k]<<"\t"; cout<<"\nAMOUNT:"<<amount[k]<<"\t"; cout<<"\
nPRICE:"<<pris[k]<<endl;
}
} void dept::sell(void)
{
cout<<"\nEnter product code:\n";
cin>>code; cout<<"\nEnter product
price:\n"; cin>>price;
}
void dept::total_items(void)
{
cout<<"\n\nITEM CODE:"<<code<<"\n\nITEM PRICE:"<<price;
}
int main()
{
dept d[10];
static int j=0;
int x,i=0,p,s=0;
clrscr(); do{
cout<<"\nENTER YOUR CHOICE:\n";
cout<<"\n1. Show all stored items:";
cout<<"\n2. Add an old item:"; cout<<"\
n3. Add a new item:"; cout<<"\n4. Sell an
item:"; cout<<"\n5. Total sold:"; cout<<"\
n6. Show total items sold:"; cout<<"\n7.
Quit";
cin>>x; switch(x)
{ case 1: d[i].show();
break; case 2:
d[i].add_old();
d[i].show(); break; case
3: d[i].add_new();
d[i].show(); break;
case 4: d[i].sell(); i++,j++; break;
case 5:{ cout<<"Total Sold:";
s=0;
for(p=0;p<j;p++)
{ s=s+d[p].price;
}
cout<<s; cout<<"TK.\n";
}
break; case 6:
for(i=0;i<j;i++)
{ d[i].total_items();
}
break; case 7:
break;
}
} while(x!=7);
getch(); return
0;
}
3
Entering choice No:1
4
CONCLUSION
In conclusion, constructors are a crucial concept in Java programming that are used to initialize
objects of a class. They are special methods with the same name as the class and no return type,
and they are called when an object is created using the “new” keyword. Constructors can be
overloaded and can call other constructors using the “this” keyword, allowing for constructor
chaining and code reuse. By understanding constructors and how to use them effectively, you
can create more robust and flexible Java applications. Thank you for reading this article, and I
hope that it has provided you with valuable insights that you can apply to your own Java
projects.
Conclusion. According to C++ copy constructor, when an object is made, a function Object()
{ [native code] } is a special type of member function that is called automatically. A function
Object() { [native code] } in C++ has the same name as the class it belongs to, and it does not
have a return form.
You declare and implement a constructor just like you would any other method in your class.
The name of the constructor must be the same as the name of the class and, if you provide more
than one constructor, the arguments to each constructor must differ in number or in type from
the others.
In conclusion, constructors are a crucial concept in Java programming that are used to initialize
objects of a class. They are special methods with the same name as the class and no return type,
and they are called when an object is created using the “new” keyword. Constructors can be
overloaded and can call other constructors using the “this” keyword, allowing for constructor
chaining and code reuse. By understanding constructors and how to use them effectively, you
can create more robust and flexible Java applications. Thank you for reading this article, and I
hope that it has provided you with valuable insights that you can apply to your own Java
projects.
Conclusion. According to C++ copy constructor, when an object is made, a function Object()
{ [native code] } is a special type of member function that is called automatically. A function
Object() { [native code] } in C++ has the same name as the class it belongs to, and it does not
have a return form.
You declare and implement a constructor just like you would any other method in your class.
The name of the constructor must be the same as the name of the class and, if you provide more
than one constructor, the arguments to each constructor must differ in number or in type from
the others.
5
FUTURE SCOPE
The scope of a name declared inside a constructor is the same as the scope of any local
name (the fact that it is a constructor makes no difference whatsoever): the scope of the
name extends to the end of the block in which the name is declared (and it can have
"holes" when the name is hidden by a declaration of an What is the scope of constructor
variables?
Scope is defined as where a variable is accessible or can be used. Local variables can be
declared in the body of constructors and methods. These variables may only be used
within the constructor or method and cannot be declared to be public or private.
What is a Default Constructor in Java? Java automatically provides a default constructor when
a class is defined without explicit constructors. The default constructor initializes the object
with default values, which means it sets the variables to their default values, like 0 for integers
and null for objects
The scope of a name declared inside a constructor is the same as the scope of any local name
(the fact that it is a constructor makes no difference whatsoever): the scope of the name extends
to the end of the block in which the name is declared (and it can have "holes" when the name is
hidden by a declaration of an What is the default scope of constructor?
What is a Default Constructor in Java? Java automatically provides a default constructor when
a class is defined without explicit constructors. The default constructor initializes the object
with default values, which means it sets the variables to their default values, like 0 for integers
and null for objects
What is the scope of constructor variables?
Scope is defined as where a variable is accessible or can be used. Local variables can be
declared in the body of constructors and methods. These variables may only be used within the
constructor or method And cannot be declared to be public or private.