OOSD IMP QUESTIONS
OOSD IMP QUESTIONS
Basically, the approach of SA/SD is based on the Data Flow Diagram. It is easy to understand
SA/SD but it focuses on well-defined system boundary whereas the JSD approach is too
complex and does not have any graphical representation.
SA/SD is combined known as SAD and it mainly focuses on the following 3 points:
1. System
2. Process
3. Technology
SA/SD involves 2 phases:
1. Analysis Phase: It uses Data Flow Diagram, Data Dictionary, State Transition diagram
and ER diagram.
2. Design Phase: It uses Structure Chart and Pseudo Code.
1. Analysis Phase:
Analysis Phase involves data flow diagram, data dictionary, state transition diagram, and
entity-relationship diagram.
Data Flow Diagram:
In the data flow diagram, the model describes how the data flows through the system. We can
incorporate the Boolean operators and & or link data flow when more than one data flow may
be input or output from a process.
For example, if we have to choose between two paths of a process we can add an operator or
and if two data flows are necessary for a process we can add an operator. The input of the
process “check-order” needs the credit information and order information whereas the output
of the process would be a cash-order or a good-credit-order.
Data Dictionary:
The content that is not described in the DFD is described in the data dictionary. It defines the
data store and relevant meaning. A physical data dictionary for data elements that flow
between processes, between entities, and between processes and entities may be included. This
would also include descriptions of data elements that flow external to the data stores.
A logical data dictionary may also be included for each such data element. All system names,
whether they are names of entities, types, relations, attributes, or services, should be entered in
the dictionary.
4. ER Diagram:
ER diagram specifies the relationship between data store. It is basically used in database
design. It basically describes the relationship between different entities .
2. Design Phase:
Design Phase involves structure chart and pseudocode.
1. Structure Chart:
It is created by the data flow diagram. Structure Chart specifies how DFS’s processes are
grouped into tasks and allocated to the CPU. The structured chart does not show the
working and internal structure of the processes or modules and does not show the
relationship between data or data flows. Similar to other SASD tools, it is time and cost-
independent and there is no error-checking technique associated with this tool. The modules
of a structured chart are arranged arbitrarily and any process from a DFD can be chosen as
the central transform depending on the analysts’ own perception. The structured chart is
difficult to amend, verify, maintain, and check for completeness and consistency.
2. Pseudo Code: It is the actual implementation of the system. It is an informal way of
programming that doesn’t require any specific programming language or technology .
Advantages of Structured Analysis and Structured Design (SA/SD):
1. Clarity and Simplicity: The SA/SD method emphasizes breaking down complex systems
into smaller, more manageable components, which makes the system easier to understand
and manage.
2. Better Communication: The SA/SD method provides a common language and framework
for communicating the design of a system, which can improve communication between
stakeholders and help ensure that the system meets their needs and expectations.
3. Improved maintainability: The SA/SD method provides a clear, organized structure for a
system, which can make it easier to maintain and update the system over time.
4. Better Testability: The SA/SD method provides a clear definition of the inputs and outputs
of a system, which makes it easier to test the system and ensure that it meets its
requirements.
Disadvantages of Structured Analysis and Structured Design (SA/SD):
1. Time-Consuming: The SA/SD method can be time-consuming, especially for large and
complex systems, as it requires a significant amount of documentation and analysis.
2. Inflexibility: Once a system has been designed using the SA/SD method, it can be difficult
to make changes to the design, as the process is highly structured and documentation-
intensive.
3. Limited Iteration: The SA/SD method is not well-suited for iterative development, as it is
designed to be completed in a single pass.
The main focus is on the process and The main focus is on data structure and
procedures of the system. real-world objects that are important.
Structured Analysis Object-Oriented Analysis
This technique is old and is not This technique is new and is mostly
preferred usually. preferred.
Limitations of JSD
1. It is a poor methodology for high level analysis and database design.
2. JSD is a complex methodology due to pseudo code representation.
3. It is less graphically oriented as compared to SA/SD or OMT.
4. It is a bit complex and difficult to understand.
Object-oriented programming can be defined as a programming model which is based upon the
concept of objects. Objects contain data in the form of attributes and code in the form of
methods. In object-oriented programming, computer programs are designed using the concept
of objects that interact with the real world. Object-oriented programming languages are various
but the most popular ones are class-based, meaning that objects are instances of classes, which
also determine their types.
Languages used in Object-Oriented Programming:
Java, C++, C#, Python,
PHP, JavaScript, Ruby, Perl,
Objective-C, Dart, Swift, Scala.
Below are some of the differences between procedural and object-oriented programming:
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any Object-oriented programming provides data
proper way of hiding data so it is less secure. hiding so it is more secure.
Procedural Oriented Programming Object-Oriented Programming
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
UNIT-4
Q1. What are Macros?
In C++, a macro is part of code that is expanded to its value. Macros are defined using the
#define directive. They provide a way to create symbolic constants and code snippets that can
be reused throughout a program. Macros are processed by the C++ preprocessor, which runs
before the actual compilation. During preprocessing, macros are replaced with their
corresponding values, making it an effective tool for code generation and simplification.
Syntax
The syntax for defining a macro in C++ is as follows:
#define MACRO_NAME macro_definition
MACRO_NAME: It is the name we give to the macro, that’s usually in uppercase to
differentiate it from ordinary C++ identifiers.
macro_definition: It is the code that the preprocessor will substitute whenever the macro
is used.
Example of Macro
Let’s explore a simple example of a macro in C++. Suppose we want to create a macro to
calculate the square of a number. Here’s how we can define and use a macro:
// C++ program to illustrate the macro definition
#include <iostream>
using namespace std;
// Define a macro to calculate the square of a number
#define SQUARE(x) (x * x)
int main()
{
int n = 7;
int result = SQUARE(n); // Expands to: (n * n)
cout << "Square of " << n << " is " << result;
return 0;
}
Output
Square of 7 is 49
// Inline function
inline int Maximum(int a, int b)
{
return (a > b) ? a : b;
}
return 0;
}
Output:
Max (100, 1000): 1000
Max (20, 0): 20
2. Macro :
It is also called preprocessors directive. The macros are defined by the #define keyword.
Before the program compilation, the preprocessor examines the program whenever the
preprocessor detects the macros then preprocessor replaces the macro by the macro definition.
Syntax of Macro:
#define MACRO_NAME Macro_definition
Example of Macro:
#include <iostream>
using namespace std;
return 0;
}
Output:
Max (100, 1000):1000
Max (20, 0):20
Through inline function, the class’s Whereas macro can’t access the class’s data
2.
data members can be accessed. members.
3. In the case of inline function, the Whereas in the case of macros, the program
S.NO Inline Macro
In C++, inline may be defined either Whereas the macro is all the time defined at
5.
inside the class or outside the class. the beginning of the program.
7. Inline is not as widely used as macros. While the macro is widely used.
Inline is not used in competitive While the macro is very much used in
8.
programming. competitive programming.
Inline function is terminated by the While the macro is not terminated by any
9.
curly brace at the end. symbol, it is terminated by a new line.
Example
int myFunction(int x)
float myFunction(float x)
double myFunction(double x, double y)
Consider the following example, which have two functions that add numbers of
different type:
Example
int plusFuncInt(int x, int y) {
return x + y;
}
int main() {
int myNum1 = plusFuncInt(8, 5);
double myNum2 = plusFuncDouble(4.3, 6.26);
cout << "Int: " << myNum1 << "\n";
cout << "Double: " << myNum2;
return 0;
}
Instead of defining two functions that should do the same thing, it is better to
overload one.
Example
int plusFunc(int x, int y) {
return x + y;
}
int main() {
int myNum1 = plusFunc(8, 5);
double myNum2 = plusFunc(4.3, 6.26);
cout << "Int: " << myNum1 << "\n";
cout << "Double: " << myNum2;
return 0;
}
Q3. Default Arguments in C++
A default argument is a value provided in a function declaration that is automatically assigned by
the compiler if the calling function doesn’t provide a value for the argument. In case any value is
passed, the default value is overridden.
1) The following is a simple C++ example to demonstrate the use of default arguments. Here, we
don’t have to write 3 sum functions; only one function works by using the default values for 3rd
and 4th arguments.
// CPP Program to demonstrate Default Arguments
#include <iostream>
using namespace std;
// Driver Code
int main()
{
// Statement 1
cout << sum(10, 15) << endl;
// Statement 2
cout << sum(10, 15, 25) << endl;
// Statement 3
cout << sum(10, 15, 25, 30) << endl;
return 0;
}
Output
25
50
80
#include <iostream>
using namespace std;
class base {
public:
virtual void print() { cout << "print base class\n"; }
int main()
{
base* bptr;
derived d;
bptr = &d;
// Virtual function, binded at runtime
bptr->print();
return 0;
}
Everything in C++ is associated with classes and objects, along with its
attributes and methods. For example: in real life, a car is an object. The car
has attributes, such as weight and color, and methods, such as drive and
brake.
Attributes and methods are basically variables and functions that belongs
to the class. These are often referred to as "class members".
A class is a user-defined data type that we can use in our program, and it
works as an object constructor, or a "blueprint" for creating objects.
Create a Class
To create a class, use the class keyword:
Example
Create a class called "MyClass":
Example explained
The class keyword is used to create a class called MyClass.
The public keyword is an access specifier, which specifies that
members (attributes and methods) of the class are accessible from
outside the class. You will learn more about access specifiers later.
Inside the class, there is an integer variable myNum and a string
variable myString. When variables are declared within a class, they are
called attributes.
At last, end the class definition with a semicolon ;.
Create an Object
In C++, an object is created from a class. We have already created the
class named MyClass, so now we can use this to create objects.
To access the class attributes (myNum and myString), use the dot syntax
(.) on the object:
Example
Create an object called "myObj" and access the attributes:
int main() {
MyClass myObj; // Create an object of MyClass
UNIT-5
Q1. Difference between Public and Private
Public Private
o Default constructor
o Parameterized constructor
#include <iostream>
using namespace std;
class Employee
{
public:
Employee()
{
cout<<"Default Constructor Invoked"<<endl;
}
};
int main(void)
{
Employee e1; //creating an object of Employee
Employee e2;
return 0;
}
#include <iostream>
using namespace std;
class Employee {
public:
int id;//data member (also instance variable)
string name;//data member(also instance variable)
float salary;
Employee(int i, string n, float s)
{
id = i;
name = n;
salary = s;
}
void display()
{
cout<<id<<" "<<name<<" "<<salary<<endl;
}
};
int main(void) {
Employee e1 =Employee(101, "Sonoo", 890000); //creating an object of Em
ployee
Employee e2=Employee(102, "Nakul", 59000);
e1.display();
e2.display();
return 0;
}
Output:
......
}
Here, the const qualifier is optional but is added so that we do not modify the obj
by mistake.
public:
// Parameterized constructor
student(int, string, double);
// Copy constructor
student(student& t)
{
rno = t.rno;
name = t.name;
fee = t.fee;
cout << "Copy Constructor Called" << endl;
}
// Function to display student details
void display();
};
int main()
{
// Create student object with parameterized constructor
student s(1001, "Manjeet", 10000);
s.display();
return 0;
}
Output
1001 Manjeet 10000
Copy Constructor Called
1001 Manjeet 10000
Where the return type is the type of value returned by the function.
#include <iostream>
using namespace std;
class Test
{
private:
int num;
public:
Test(): num(8){} //Constructor to initialize count to 8
void operator ++() {
num = num+2;
}
void Print() {
cout<<"The Count is: "<<num;
}
};
int main()
{
Test tt;
++tt; // calling of a function "void operator ++()"
tt.Print();
return 0;
}
The Count is: 10
Distinguished by the number and Defined for specific types, often within t
types of parameters. class definition of those types.
#include <iostream>
using namespace std;
int main()
{
int x = 10; // integer x
char y = 'a'; // character c
return 0;
Output
x = 107
y = a
z = 108
Explicit Type Conversion: This process is also called type casting and it is user-
defined. Here the user can typecast the result to make it of a particular data type. In
C++, it can be done by two ways:
Converting by assignment: This is done by explicitly defining the required type
in front of the expression in parenthesis. This can be also considered as forceful
casting. Syntax:
(type) expression
where type indicates the data type to which the final result is
converted. Example:
// C++ program to demonstrate
// explicit type casting
#include <iostream>
using namespace std;
int main()
{
double x = 1.2;
return 0;
}
Output
Sum = 2
Conversion using Cast operator: A Cast operator is an unary operator which
forces one data type to be converted into another data type. C++ supports four types
of casting:
1. Static Cast
2. Dynamic Cast
3. Const Cast
4. Reinterpret Cast
#include <iostream>
using namespace std;
int main()
{
float f = 3.5;
cout << b;
}
Output
3
Advantages of Type Conversion:
This is done to take advantage of certain features of type hierarchies or type
representations.
It helps to compute expressions containing variables of different data types.