B.C.A. Sem-2
Course Code: LBC0204 | Course Title: C++ Programming (3 Credits) |
Course Objectives: –
Ø To gain the basic knowledge on object-oriented concepts. Ø To understand the role of inheritance, polymorphism, dynamic binding and generic structures in building reusable code Ø To get a basic knowledge of object-oriented concepts. Ø To master in programming related to classes inheritance using C++ |
Course Contents
Unit | Unit description | Learning Outcome |
1 | Introduction: Overview of oops, Differences between OOP and Procedure Oriented programming, Structure of a C/C++ program, Differences between C/C++, Data Types in C++, Identifier and Keywords, Constants, C++ Operators, Type Conversion, Variable declaration, statements, Expressions, Features of iostream.h, Input and Output. | This module has been designed as per BTL 1 & 2. |
2 | Statements & Arrays: Selection Statements , Iteration Statements , Jump statements, Block Statements, Single-Dimension Arrays, wo-Dimensional Arrays, Multidimensional Arrays. | This module has been designed as per BTL 3&5. |
3 | Data Abstraction, Polymorphism and Inheritance: Class Definition, controlling access to other functions, Memory Allocation, Different Types of Constructors, Destructor, Dynamic Creation and Destruction of Objects, Overloading functions and operators, Overloading New and Delete operators. Derived Classes, Syntax of, Base Class, Types of Inheritance, Overloading Inherited Member Function. | This module has been designed as per BTL 3&4. |
4 | Functions: The General Form of a Function, Scope Rules of Functions, Function Arguments, The return Statement. | This module has been designed as per BTL 3 & 6. |
5 | Structures, Unions, Enumerations, and User-Defined Types: Structures, Arrays of Structures, Structure Pointers, Unions, Enumerations, Using sizeof to Ensure Portability. |
This module has been designed as per BTL 3 & 6. |
6 | Operator Overloading: Creating member operator function, creating prefix and postfix forms, operator overloading using friend function, overloading new and delete. | This module has been designed as per BTL 3 &6. |
7 | Inheritance: Base class access control, Inheritance and protected members, Inheritance and Multiple base classes, constructors, Destructors and Inheritance. | This module has been designed as per BTL 3. |
8 | Virtual functions and polymorphism: Static and Dynamic bindings, virtual functions, dynamic binding through virtual functions, virtual function call mechanism, implications of polymorphic use of classes, virtual destructors, calling virtual functions in a base class constructor. | This module has been designed as per BTL 3&4. |
9 | File I/O: Standard I/O Using C functions, stream I/O in C++, formatted I/O, File I/O, generic Classes in C++ and the file classes, put() and get(), read() and write(), peek and putbeack(). | This module has been designed as per BTL 3&4. |
10 | Templates: Necessity of Templates, generic classes using Macros, class templates, Function Templates, Advantages of Templates. | This module has been designed as per BTL 4&5. |
11 | Exception and: Benefits of exception handling, troubles with standard C functions, exception handling mechanism in C++. | This module has been designed as per BTL 3. |
12 | File Handling: hierarchy of file stream classes, opening and closing files, file modes, testing for errors, file pointers and their manipulations, ASCII & Binary files, sequential and random-access files. | This module has been designed as per BTL 3 &6 |
Textbook References: –
Other References:
|
(Bloom’s Taxonomy: BT level 1: Remembering; BT level 2: Understanding; BT level 3: Applying; BT level 4: Analyzing; BT level 5: Evaluating; BT level 6: Creating)
Syllabus
Program | Bachelor of Computer Applications |
Semester | II |
Course Title | C++ Programming Practical |
Course Code | LBC0222 |
Course Credits | 02 |
Course Type | Core Practical Course |
- Course Summary
This course aims to provide a strong foundation in object-oriented programming principles and techniques using C++. Students are taught the principles of classes and objects. The students are also taught templates, polymorphism, inheritance, exception handling, data encapsulation, and abstraction. Students are taught to employ constructors, destructors, and operator overloading capabilities to create a range of programs.
- Course Contents
Units | UnitsDescription | Unit Outcomes
After the successful completion of the unit, the learner should be able to: |
1 | Introduction to OOP
· An overview of data encapsulation, polymorphism, and abstraction · C++ program: Example of a Structure and Hello World · Talk about header files, data types, and C++ keywords |
1. Talk about OOP features. 2. Put in place a basic C++ program. 3. Talk about keywords and common library files. |
2 | C++Complier
· Compiler history · Syntax and semantic mistakes · Various offline and online compilers |
1. Use online and offline compilers to demonstrate C++ programs. 2. Comprehend the C++ compiler installation process. |
3 | Sublime Editor and Cygwin Compiler
· Introduction to sublime editor · Different menus and settings in sublime · Installation of Cygwin and introduction to GCC |
Understand installation of editor and compiler using sublime and Cygwin package. |
4 | ListofExperiments | |
1) 1 | Write a program to print “Hello world” | |
2) 2 | Demonstration of Data Types and Variables in C++ | |
3) 3 | Basic Arithmetic Operations in C++ | |
4) 4 | Finding the Largest Number using If-Else in C++ | |
5) 5 | Write a program to find Fibonacci series. | |
6) 6 | Write a program for simple calculator using Switch Statement. | |
7) 7 | Write a program for printing number using While loop. | |
8) 8 | Write a program for Printing multiplication table using For Loop | |
9) 9 | Write a program for Printing Even Numbers Using Do-While Loop. | |
10) 10 | Write a program for breaking out of a Loop using jump statements. | |
11) 11 | Write a program skipping iterations using Continue Statement. | |
12) 12 | Write a program calculating sum of array(1-D) elements. | |
13) 13 | Write a program matrix Addition. | |
14) 14 | Write a program to define a simple basic class. | |
15) 15 | Write a program to define a simple basic class using access specifier. | |
16) 16 | Write a program to demonstrate dynamic memory allocation for arrays. | |
17) 17 | Write a program to demonstrate default, parameterized, and copy Constructors. | |
18) 18 | Write a program to demonstrate the use of Destructor. | |
19) 19 | Write a program to demonstrate function overloading. | |
20) 20 | Write a program to calculate the square of a number. | |
21) 21 | Write a program to define and using structure. | |
22) 22 | Write a program to storing multiple persons in an array of Structures | |
23) 23 | Write a program to demonstrate Union. | |
24) 24 | Write a program to demonstrate Enumerations. | |
25) 25 | Write a program to Overloading the + Operator for a Complex Number Class. | |
26) 26 | Write a program to Overloading the ++ Operator for a Counter Class. | |
27) 27 | Write a program to Overloading the << Operator for a Complex Number Class using friend function. | |
28) 28 | Write a program to Overloading new and delete Operators. | |
29) 29 | Write a program to explain Single inheritance. | |
30) 30 | Write a program to explain Multiple inheritance. | |
31) 31 | Write a program to demonstrate Virtual Functions and Dynamic Binding in C++. | |
32) 32 | Write a program to Demonstrating Virtual Destructors in C++ | |
33) 33 | Write a program to demonstrating File I/O with in C++ | |
34) 34 | Write a program to demonstrating read() and write() Functions in C++ | |
35) 35 | Write a program to demonstrating class templates in C++. | |
36) 36 | Write a program to demonstrating function templates in C++. | |
37) 37 | Illustrate the exception for divide overflow error for any mathematical expression. |
- Course Resources
- Essential Reading
- Course Self-Learning Material
- Balagurusamy., 2011, Object Oriented Programming with C++, 4th Edition, Tata Mc Graw Education Hill.
- Herbert Schildt,2003,The Complete Reference C++,4thEdition,TataMcGrawHill
- Recommended Reading
- Robert Lafore, 2008, Object-oriented Programming with C++, 4th edition, Pearson Education, India.
- Stephen Prata, C++ Primer Plus: Teach Yourself Object Oriented Programming, 2ndedition,waite group
- Object Oriented Programming in C++, 3rd Edition, R. Lafore, Galigotia Publications Pvt Ltd.
- Websites
- https://www.coursera.org/
- http://nptel.ac.in/
- Essential Reading
- Other Electronic Resources
- Course Video Lectures on LMS
Unit 1: Introduction to OOP
Overview: This unit introduces the fundamental concepts of Object-Oriented Programming (OOP), focusing on data abstraction, encapsulation, and polymorphism. Students will learn the basic structure of a C++ program, understand the use of header files, and explore the various data types and keywords in C++.
Key Topics:
- Data Abstraction and Encapsulation:
- Explanation of data hiding and encapsulation, using classes to bundle data and functions.
- Implementation of data abstraction through abstract classes and interfaces.
- Polymorphism:
- Introduction to polymorphism, including function overloading and operator overloading.
- Concept of runtime polymorphism using virtual functions and pointers.
- C++ Program Structure:
- Basic structure of a C++ program, including headers, main function, and syntax.
- Example of a simple “Hello World” program.
Unit 2: C++ Compiler
Overview: This unit provides an introduction to C++ compilers, explaining the differences between syntax and semantic errors. It covers the use of both online and offline compilers, and demonstrates how to compile and execute C++ programs.
Key Topics:
- Understanding Compilers:
- Definition and role of compilers in programming.
- Differences between interpreters and compilers.
- Error Handling:
- Identification and resolution of syntax errors and semantic errors.
- Using Compilers:
- Overview of popular C++ compilers like GCC, Clang, and Microsoft Visual C++.
- Steps to compile and run a C++ program using these compilers.
The C++ compiler is used to compile a program. A C++ program is processed by the compiler to produce output or results. The C++ compiler is a system program that translates a C++ program into machine language or a low-level language. The C++ program, known as the source program, is analyzed by the compiler for errors, which then generates the machine code. This machine code is the executable form of the program. The source program is typically saved with the extension .CPP, while the executable form is generated as a .exe file. Figure 1.1 illustrates the operations of the compiler.
Figure1.1 C++Compiler
Compilation errors are issues that need to be resolved before the code can be successfully compiled. These errors are identified by the compiler and are therefore called compile-time errors. Compilation errors can include syntax errors or semantic errors.
Syntax errors occur when the rules of the programming language are violated. For example, using uppercase letters for C++ reserved words or incorrectly using parentheses can result in syntax errors. Here are some common syntax errors:
- Missing Parenthesis (})
- Unknown variable
- Missing semicolon
- Lvalue required
Run-time errors occur after successful compilation, during the execution of the program. Examples of run-time errors include division by zero and errors arising from incorrect data type usage. Unlike compile-time errors, run-time errors are not detected by the compiler but become apparent during program execution. Division by zero is a common example of a run-time error.
There are various C++ compilers and editors available. Editors are used for writing C++ programs, while C++ compilers can be used either online or as installed system software on your computer.
Compilers that can be installed on your computer are available for download as executable files (.exe). Some of these include:
- Borland C++ Compiler
- Apple C++
- Bloodshed Dev-C++
- Clang C++
- Cygwin (GNU C++)
- Digital Mars C++
- DJ Delorie’s C++ Development System for DOS/Windows (GNU C++)
- IBM C++ for IBM Power, SystemZ, BlueGene, and Cell
- Intel C++ for non-commercial development
- Sun Studio
C++ programs can also be compiled and executed online through various websites. Some options include:
C++ program compilation and execution on https://www.programiz.com is shown in theFigure1.2.
Figure1.2 A Screen shot to use C++programming online compiler
Unit 3: Sublime Editor and Cygwin Compiler
Overview: This unit focuses on using the Sublime Text editor and the Cygwin compiler to write and execute C++ programs. It includes installation instructions, configuration settings, and practical tips for efficient coding.
Key Topics:
- Sublime Text Editor:
- Features and benefits of using Sublime Text for C++ programming.
- Installation and basic configuration for C++ development.
- Cygwin Compiler:
- Installation steps for the Cygwin environment on Windows.
- Configuring Cygwin for C++ compilation.
- Writing and Running C++ Programs:
- Creating, editing, and saving C++ files in Sublime Text.
- Compiling and executing programs using the Cygwin terminal.
Example Program:
#include
using namespace std;
int main() {
int a = 5, b = 10;
cout<< “Sum: ” << a + b <<endl;
return 0;
}
Compiling and Running:
g++ -o sumProgram sumProgram.cpp
./sumProgram
Unit-4
Programs
Experiment-1 Write a program to print “Hello world”
#include
using namespace std;
int main() {
cout<< “Hello, World!” <<endl;
return 0;
}
Experiment-2Demonstration of Data Types and Variables in C++
#include
using namespace std;
int main() {
int integerVar = 5;
float floatVar = 3.14;
char charVar = ‘A’;
bool boolVar = true;
cout<< “Integer: ” <<integerVar<<endl;
cout<< “Float: ” <<floatVar<<endl;
cout<< “Character: ” <<charVar<<endl;
cout<< “Boolean: ” <<boolVar<<endl;
return 0;
}
Experiment-3Basic Arithmetic Operations in C++
#include
using namespace std;
int main() {
int a = 10, b = 20;
cout<< “Addition: ” << (a + b) <<endl;
cout<< “Subtraction: ” << (a – b) <<endl;
cout<< “Multiplication: ” << (a * b) <<endl;
cout<< “Division: ” << (a / b) <<endl;
cout<< “Modulus: ” << (a % b) <<endl;
return 0;
}
Experiment-3Finding the Largest Number using If-Else in C++
#include
using namespace std;
int main() {
int a, b, c;
cout<< “Enter three numbers: “;
cin>> a >> b >> c;
if (a > b && a > c) {
cout<< “a is the largest” <<endl;
} else if (b > a && b > c) {
cout<< “b is the largest” <<endl;
} else {
cout<< “c is the largest” <<endl;
}
return 0;
}
Experiment-4Write a program to find Fibonacci series.
#include
using namespace std;
int main() {
int n;
int t1 = 0, t2 = 1, nextTerm = 0;
cout<< “Enter the number of terms: “;
cin>> n;
cout<< “Fibonacci Series: ” << t1 << “, ” << t2 << “, “;
for (int i = 3; i<= n; ++i) {
nextTerm = t1 + t2;
cout<<nextTerm<< “, “;
t1 = t2;
t2 = nextTerm;
}
return 0;
}
Experiment-5Write a program for simple calculator using Switch Statement.
#include
using namespace std;
int main() {
char operation;
float num1, num2;
cout<< “Enter operator (+, -, *, /): “;
cin>> operation;
cout<< “Enter two operands: “;
cin>> num1 >> num2;
switch (operation) {
case ‘+’:
cout<< “Result: ” << num1 + num2 <<endl;
break;
case ‘-‘:
cout<< “Result: ” << num1 – num2 <<endl;
break;
case ‘*’:
cout<< “Result: ” << num1 * num2 <<endl;
break;
case ‘/’:
if (num2 != 0)
cout<< “Result: ” << num1 / num2 <<endl;
else
cout<< “Division by zero error!” <<endl;
break;
default:
cout<< “Invalid operator!” <<endl;
break;
}
return 0;
}
Output:
Enter operator (+, -, *, /): +
Enter two operands: 5 3
Result: 8
Experiment-5Write a program forprinting number using While loop.
#include
using namespace std;
int main() {
int i = 1, n;
cout<< “Enter the number of iterations: “;
cin>> n;
while (i<= n) {
cout<<i<< ” “;
i++;
}
return 0;
}
Output:
Enter the number of iterations: 5
1 2 3 4 5
Experiment-6Write a program for Printing multiplication table using For Loop
#include
using namespace std;
int main() {
int num;
cout<< “Enter a number to display its multiplication table: “;
cin>> num;
for (int i = 1; i<= 10; ++i) {
cout<< num << ” * ” <<i<< ” = ” << num * i<<endl;
}
return 0;
}
Output:
Enter a number to display its multiplication table: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
Experiment-7Write a program for Printing Even Numbers Using Do-While Loop.
#include
using namespace std;
int main() {
int n, i = 2;
cout<< “Enter the upper limit: “;
cin>> n;
cout<< “Even numbers up to ” << n << ” are: “;
do {
cout<<i<< ” “;
i += 2;
} while (i<= n);
return 0;
}
Output:
Enter the upper limit: 10
Even numbers up to 10 are: 2 4 6 8 10
Experiment-8Write a program for breaking out of a Loop using jump statements.
#include
using namespace std;
int main() {
int n;
cout<< “Enter a number (negative to exit): “;
while (cin>> n) {
if (n < 0) {
break;
}
cout<< “You entered: ” << n <<endl;
cout<< “Enter a number (negative to exit): “;
}
cout<< “Exited the loop.” <<endl;
return 0;
}
Output:
Enter a number (negative to exit): 5
You entered: 5
Enter a number (negative to exit): 3
You entered: 3
Enter a number (negative to exit): -1
Exited the loop.
Experiment-9Write a program skipping iterations using Continue Statement.
#include
using namespace std;
int main() {
int n;
cout<< “Enter the upper limit: “;
cin>> n;
for (int i = 1; i<= n; ++i) {
if (i % 2 == 0) {
continue;
}
cout<<i<< ” “;
}
return 0;
}
Output:
Enter the upper limit: 10
1 3 5 7 9
Experiment-10Write a program calculating sum of array(1-D)elements.
#include
using namespace std;
int main() {
int n;
cout<< “Enter the number of elements: “;
cin>> n;
int arr[n];
cout<< “Enter ” << n << ” elements: “;
for (int i = 0; i< n; ++i) {
cin>>arr[i];
}
int sum = 0;
for (int i = 0; i< n; ++i) {
sum += arr[i];
}
cout<< “Sum of elements: ” << sum <<endl;
return 0;
}
Output:
Enter the number of elements: 5
Enter 5 elements: 1 2 3 4 5
Sum of elements: 15
Experiment-11Write a program matrix Addition.
#include
using namespace std;
int main() {
int rows, cols;
cout<< “Enter the number of rows and columns: “;
cin>> rows >> cols;
int matrix1[rows][cols], matrix2[rows][cols], sum[rows][cols];
cout<< “Enter elements of first matrix:\n”;
for (int i = 0; i< rows; ++i) {
for (int j = 0; j < cols; ++j) {
cin>> matrix1[i][j];
}
}
cout<< “Enter elements of second matrix:\n”;
for (int i = 0; i< rows; ++i) {
for (int j = 0; j < cols; ++j) {
cin>> matrix2[i][j];
}
}
for (int i = 0; i< rows; ++i) {
for (int j = 0; j < cols; ++j) {
sum[i][j] = matrix1[i][j] + matrix2[i][j];
}
}
cout<< “Sum of matrices:\n”;
for (int i = 0; i< rows; ++i) {
for (int j = 0; j < cols; ++j) {
cout<< sum[i][j] << ” “;
}
cout<<endl;
}
return 0;
}
Output:
Enter the number of rows and columns: 2 2
Enter elements of first matrix:
1 2
3 4
Enter elements of second matrix:
5 6
7 8
Sum of matrices:
6 8
10 12
Experiment-12Write a program to define a simple basic class.
#include
using namespace std;
class Rectangle {
public:
int length;
int width;
int area() {
return length * width;
}
};
int main() {
Rectangle rect;
rect.length = 10;
rect.width = 5;
cout<< “Area of rectangle: ” <<rect.area() <<endl;
return 0;
}
Output:
Area of rectangle: 50
Experiment-13Write a program to define a simple basic class using access specifier.
#include
using namespace std;
class Circle {
private:
double radius;
public:
void setRadius(double r) {
radius = r;
}
double getRadius() {
return radius;
}
double area() {
return 3.14159 * radius * radius;
}
};
int main() {
Circle circle;
circle.setRadius(5.0);
cout<< “Radius: ” <<circle.getRadius() <<endl;
cout<< “Area of circle: ” <<circle.area() <<endl;
return 0;
}
Output:
Radius: 5
Area of circle: 78.53975
Experiment-14Write a program to demonstrate dynamic memory allocation for arrays.
#include
using namespace std;
int main() {
int n;
cout<< “Enter the number of elements: “;
cin>> n;
int *arr = new int[n];
cout<< “Enter ” << n << ” elements: “;
for (int i = 0; i< n; ++i) {
cin>>arr[i];
}
cout<< “You entered: “;
for (int i = 0; i< n; ++i) {
cout<<arr[i] << ” “;
}
cout<<endl;
delete[] arr; // Deallocate the memory
return 0;
}
Output:
Enter the number of elements: 3
Enter 3 elements: 1 2 3
You entered: 1 2 3
Experiment-15Write a program to demonstrate default, parameterized, and copy Constructors.
#include
using namespace std;
class Complex {
public:
int real;
int imag;
// Default constructor
Complex() : real(0), imag(0) {}
// Parameterized constructor
Complex(int r, int i) : real(r), imag(i) {}
// Copy constructor
Complex(const Complex &c) : real(c.real), imag(c.imag) {}
void display() {
cout<< real << ” + ” <<imag<< “i” <<endl;
}
};
int main() {
Complex c1;
Complex c2(3, 4);
Complex c3(c2);
cout<< “Default constructor: “;
c1.display();
cout<< “Parameterized constructor: “;
c2.display();
cout<< “Copy constructor: “;
c3.display();
return 0;
}
Output:
Default constructor: 0 + 0i
Parameterized constructor: 3 + 4i
Copy constructor: 3 + 4i
Experiment-16Write a program to demonstrate the use of Destructor.
#include
using namespace std;
class Demo {
public:
Demo() {
cout<< “Constructor called” <<endl;
}
~Demo() {
cout<< “Destructor called” <<endl;
}
};
int main() {
Demo obj;
return 0;
}
Output:
Constructor called
Destructor called
Experiment-17 Write a program to demonstrate function overloading.
#include
using namespace std;
class Print {
public:
void display(int i) {
cout<< “Integer: ” <<i<<endl;
}
void display(double f) {
cout<< “Float: ” << f <<endl;
}
void display(string s) {
cout<< “String: ” << s <<endl;
}
};
int main() {
Print p;
p.display(5);
p.display(3.14);
p.display(“Hello, world!”);
return 0;
}
Output:
Integer: 5
Float: 3.14
String: Hello, world!
Experiment-18 Write a program to calculate the square of a number.
#include
using namespace std;
// Function declaration
int square(int num);
int main() {
int number;
cout<< “Enter a number: “;
cin>> number;
// Function call
cout<< “The square of ” << number << ” is ” << square(number) <<endl;
return 0;
}
// Function definition
int square(int num) {
return num * num;
}
Output:
Enter a number: 5
The square of 5 is 25
Experiment-19 Write a program to define and using structure.
#include
using namespace std;
struct Person {
string name;
int age;
float height;
};
int main() {
Person p1;
p1.name = “Alice”;
p1.age = 25;
p1.height = 5.6;
cout<< “Person Details:” <<endl;
cout<< “Name: ” << p1.name <<endl;
cout<< “Age: ” << p1.age <<endl;
cout<< “Height: ” << p1.height << ” feet” <<endl;
return 0;
}
Output:
Person Details:
Name: Alice
Age: 25
Height: 5.6 feet
Experiment-19 Write a program to storing multiple persons in an array of Structures
#include
using namespace std;
struct Person {
string name;
int age;
float height;
};
int main() {
Person persons[3];
persons[0] = {“Alice”, 25, 5.6};
persons[1] = {“Bob”, 30, 5.9};
persons[2] = {“Charlie”, 22, 5.8};
cout<< “Persons Details:” <<endl;
for (int i = 0; i< 3; ++i) {
cout<< “Person ” <
}
return 0;
}
Output:
Persons Details:
Person 1: Alice, Age: 25, Height: 5.6 feet
Person 2: Bob, Age: 30, Height: 5.9 feet
Person 3: Charlie, Age: 22, Height: 5.8 feet
Experiment-20 Write a program to demonstrate Union.
#include
using namespace std;
union Data {
int intVal;
float floatVal;
char charVal;
};
int main() {
Data data;
data.intVal = 10;
cout<< “Integer: ” <<data.intVal<<endl;
data.floatVal = 5.5;
cout<< “Float: ” <<data.floatVal<<endl;
data.charVal = ‘A’;
cout<< “Character: ” <<data.charVal<<endl;
return 0;
}
Output:
Integer: 10
Float: 5.5
Character: A
Experiment-21 Write a program to demonstrate Enumerations.
#include
using namespace std;
enum Color {
RED,
GREEN,
BLUE
};
int main() {
Color c = GREEN;
cout<< “Color value: ” << c <<endl;
if (c == GREEN) {
cout<< “The color is green.” <<endl;
}
return 0;
}
Output:
Color value: 1
The color is green.
Experiment-22 Write a program to Overloading the + Operator for a Complex Number Class.
#include
using namespace std;
class Complex {
private:
double real, imag;
public:
// Constructor
Complex(double r = 0, double i = 0) : real(r), imag(i) {}
// Overloading the + operator
Complex operator+(const Complex &c) {
return Complex(real + c.real, imag + c.imag);
}
// Display function
void display() {
cout<< real << ” + ” <<imag<< “i” <<endl;
}
};
int main() {
Complex c1(3.5, 2.5), c2(1.5, 4.5);
Complex c3 = c1 + c2;
cout<< “c1: “; c1.display();
cout<< “c2: “; c2.display();
cout<< “c3 (c1 + c2): “; c3.display();
return 0;
}
Output:
c1: 3.5 + 2.5i
c2: 1.5 + 4.5i
c3 (c1 + c2): 5 + 7i
Experiment-23 Write a program to Overloading the ++ Operator for a Counter Class.
#include
using namespace std;
class Counter {
private:
int count;
public:
// Constructor
Counter() : count(0) {}
// Overloading prefix ++
Counter operator++() {
++count;
return *this;
}
// Overloading postfix ++
Counter operator++(int) {
Counter temp = *this;
count++;
return temp;
}
// Display function
void display() {
cout<< “Count: ” << count <<endl;
}
};
int main() {
Counter c1;
cout<< “Original count: “;
c1.display();
++c1;
cout<< “After prefix ++: “;
c1.display();
c1++;
cout<< “After postfix ++: “;
c1.display();
return 0;
}
Output:
Original count: Count: 0
After prefix ++: Count: 1
After postfix ++: Count: 2
Experiment-23 Write a program to Overloading the << Operator for a Complex Number Class using friend function.
#include
using namespace std;
class Complex {
private:
double real, imag;
public:
// Constructor
Complex(double r = 0, double i = 0) : real(r), imag(i) {}
// Friend function to overload the << operator
friend ostream& operator<<(ostream&out, const Complex &c);
// Other member functions
void setValues(double r, double i) {
real = r;
imag = i;
}
};
ostream& operator<<(ostream&out, const Complex &c) {
out <<c.real<< ” + ” <<c.imag<< “i”;
return out;
}
int main() {
Complex c1(2.3, 4.5), c2;
cout<< “c1: ” << c1 <<endl;
c2.setValues(1.5, 3.7);
cout<< “c2: ” << c2 <<endl;
return 0;
}
Output:
c1: 2.3 + 4.5i
c2: 1.5 + 3.7i
Experiment-24 Write a program to Overloading new and delete Operators.
#include
#include
using namespace std;
class MyClass {
private:
int value;
public:
MyClass(int v = 0) : value(v) {
cout<< “Constructor called. Value: ” << value <<endl;
}
~MyClass() {
cout<< “Destructor called. Value: ” << value <<endl;
}
void* operator new(size_t size) {
cout<< “Custom new operator called. Size: ” << size <<endl;
void* p = malloc(size);
if (!p) {
bad_alloc ba;
throw ba;
}
return p;
}
void operator delete(void* p) {
cout<< “Custom delete operator called.” <<endl;
free(p);
}
};
int main() {
MyClass *obj = new MyClass(10);
delete obj;
return 0;
}
Output:
Custom new operator called. Size: 4
Constructor called. Value: 10
Destructor called. Value: 10
Custom delete operator called.
Experiment-25Write a program to explain Single inheritance.
#include
using namespace std;
// Base class
class Animal {
public:
void eat() {
cout<< “This animal eats food.” << std::endl;
}
};
// Derived class inheriting from Animal
class Dog : public Animal {
public:
void bark() {
cout<< “The dog barks.” << std::endl;
}
};
int main() {
Dog myDog;
// Calling the base class method
myDog.eat();
// Calling the derived class method
myDog.bark();
return 0;
}
Output:
This animal eats food.
The dog barks.
Experiment-26Write a program to explain Multiple inheritance.
#include
using namespace std;
// First base class
class Base1 {
public:
void greet() {
cout<< “Hello from Base1!” <<endl;
}
};
// Second base class
class Base2 {
public:
void display() {
cout<< “Hello from Base2!” <<endl;
}
};
// Derived class inheriting from both Base1 and Base2
class Derived : public Base1, public Base2 {
public:
void show() {
cout<< “Hello from Derived!” <<endl;
}
};
int main() {
Derived obj;
// Accessing methods from both base classes
obj.greet(); // Method from Base1
obj.display(); // Method from Base2
// Method from Derived class
obj.show();
return 0;
}
Output:
Hello from Base1!
Hello from Base2!
Hello from Derived!
Experiment-26Write a program to demonstrate Virtual Functions and Dynamic Binding in C++.
#include
using namespace std;
class Shape {
public:
virtual void draw() {
cout<< “Drawing a shape.” <<endl;
}
};
class Circle : public Shape {
public:
void draw() override {
cout<< “Drawing a circle.” <<endl;
}
};
class Square : public Shape {
public:
void draw() override {
cout<< “Drawing a square.” <<endl;
}
};
void render(Shape* shape) {
shape->draw(); // Dynamic binding
}
int main() {
Circle circle;
Square square;
render(&circle); // Calls Circle’s draw()
render(&square); // Calls Square’s draw()
return 0;
}
Output:
Drawing a circle.
Drawing a square.
Experiment-27Write a program to Demonstrating Virtual Destructors in C++
#include
using namespace std;
class Base {
public:
Base() { cout<< “Base constructor called.” <<endl; }
virtual ~Base() { cout<< “Base destructor called.” <<endl; }
};
class Derived : public Base {
public:
Derived() { cout<< “Derived constructor called.” <<endl; }
~Derived() { cout<< “Derived destructor called.” <<endl; }
};
int main() {
Base* ptr = new Derived();
delete ptr; // Correctly calls both Base and Derived destructors
return 0;
}
Output:
Base constructor called.
Derived constructor called.
Derived destructor called.
Base destructor called.
Experiment-28Write a program to demonstrating File I/O with in C++
#include
#include
using namespace std;
int main() {
ofstreamoutFile(“example.txt”, ios::out);
if (!outFile) {
cerr<< “File could not be opened for writing!” <<endl;
return 1;
}
outFile<< “This is a line in the file.” <<endl;
outFile.close();
ifstreaminFile(“example.txt”, ios::in);
if (!inFile) {
cerr<< “File could not be opened for reading!” <<endl;
return 1;
}
string content;
while (std::getline(inFile, content)) {
cout<< content <<endl;
}
inFile.close();
return 0;
}
Output:
This is a line in the file.
Experiment-29Write a program todemonstrating read() and write() Functions in C++
#include
#include
using namespace std;
int main() {
char data[20] = “Binary Data Test”;
// Writing binary data to a file
ofstreamoutFile(“binary.dat”, ios::binary);
outFile.write(data, sizeof(data));
outFile.close();
// Reading binary data from a file
char readData[20];
ifstreaminFile(“binary.dat”, ios::binary);
inFile.read(readData, sizeof(readData));
inFile.close();
scout << “Data read from file: ” <<readData<<endl;
return 0;
}
Output:
Data read from file: Binary Data Test
Experiment-30Write a program todemonstrating class templates in C++.
#include
using namespace std;
// Class template definition
template
class Pair {
private:
T1 first;
T2 second;
public:
// Constructor
Pair(T1 f, T2 s) : first(f), second(s) {}
// Method to display the values
void display() const {
cout<< “First: ” << first << “, Second: ” << second <<endl;
}
};
int main() {
// Pair of int and double
Pair<int, double>intDoublePair(1, 1.234);
intDoublePair.display(); // Output: First: 1, Second: 1.234
// Pair of string and int
Pair<string, int>stringIntPair(“Hello”, 42);
stringIntPair.display(); // Output: First: Hello, Second: 42
return 0;
}
Output:
First: 1, Second: 1.234
First: Hello, Second: 42
Experiment-31Write a program todemonstrating function templates in C++.
#include
using namespace std;
// Function template for finding the maximum of two values
template
T findMax(T a, T b) {
return (a > b) ? a : b;
}
int main() {
// Finding the maximum of two integers
int int1 = 10, int2 = 20;
cout<< “Max of ” << int1 << ” and ” << int2 << ” is ” <<findMax(int1, int2) <<endl;
// Finding the maximum of two doubles
double double1 = 1.234, double2 = 5.678;
cout<< “Max of ” << double1 << ” and ” << double2 << ” is ” <<findMax(double1, double2) <<endl;
// Finding the maximum of two characters
char char1 = ‘a’, char2 = ‘z’;
cout<< “Max of ‘” << char1 << “‘ and ‘” << char2 << “‘ is ‘” <<findMax(char1, char2) << “‘” <<endl;
return 0;
}
Output:
Max of 10 and 20 is 20
Max of 1.234 and 5.678 is 5.678
Max of ‘a’ and ‘z’ is ‘z’
Experiment-32Illustrate the exception for divide overflow error for any mathematical expression
#includeusing namespace std;
int main()
{
Int numerator=10, denominator=0;
try{
if(denominator==0)
throw “Exception- Division by zero!!”;
else
cout<<“Result=”<<numerator/denominator;
}
catch(const char*error){
cout<
}
}
Output
Exception-Division by zero!!Press any key to continue . ..
Course Code: LBC0203 | Course Title: Computer Organization (3 Credits) |
Course Objectives: –
Ø To impart basic concepts of computer architecture and organization, Ø To explain key skills of constructing cost-effective computer systems. Ø To familiarize the basic CPU organization. Ø To help students in understanding various memory devices. Ø To facilitate students in learning IO communication |
Course Contents
Unit | Unit description | Learning Outcome |
1 | Principles of Computer Organization: Introduction to block diagram of computer, central processing unit, Minicomputer and Microcontroller, Programming languages: Machine Language, Assembly Language, and High‐Level Language | This module has been designed as per BTL 1. |
2 | Basic Computer Organization and Design: instruction format, instruction execution cycle, registers, addressing modes, Register transfer language, | This module has been designed as per BTL 1&2. |
3 | Instruction set architecture (ISA):
Introduction to Instruction Set, |
This module has been designed as per BTL 3&4. |
4 | Data representation and Arithmetic: Fixed Point Representation, Floating Point Representation Addition and Subtraction of Signed Numbers, Multiplication of Positive Numbers, Floating Point Arithmetic: Addition and Multiplication. | This module has been designed as per BTL 4. |
5 | Machine Instructions and Programs: Assembly Language, Basic Input and Output Operations, Stacks and Queues, Subroutines. | This module has been designed as per BTL 3, 4& 5 . |
6 | Input-Output Organization: Accessing I/O Devices, Interrupts –Hardware and software Interrupt, Enabling and Disabling Interrupts, Handling Multiple Devices, Direct Memory Access. | This module has been designed as per BTL 5. |
7 | Memory Organization: memory hierarchy, main memory, auxiliary memory, associative memory, cache and virtual memory, memory interleaving. | This module has been designed as per BTL 3. |
8 | Basic Processing Unit: Some Fundamental Concepts, Execution of a Complete Instruction, Bus Structure: Data bus, address bus and control bus, Multiple Bus Organization, Hard-wired Control. | This module has been designed as per BTL 3&4. |
9 | Microprogramming Control: Types of Micro-programmed Control Unit Control memory, address sequencing, design of control unit, microprogram sequencer. | This module has been designed as per BTL 3&4. |
10 | Pipeline and vector processing: overview of Parallel Processing, Pipelining, Principles of Pipelining, Arithmetic Pipeline, Instruction Pipeline, Array processor, vector processor | This module has been designed as per BTL 4&5. |
11 | Multicores, Multiprocessors, and Clusters: The Switch from Uniprocessors to Multiprocessors, Characteristics of Multiprocessors, Shared Memory Multiprocessors, Flynn’s Classification | This module has been designed as per BTL 4. |
12 | Advance computer Architecture: Superscalar processors, study and comparison of Uniprocessors and parallel processors | This module has been designed as per BTL 4 |
Text book References: –
1. Computer Organization – Carl Hamacher, Zvonks Vranesic, SafeaZaky, Vth Edition, McGraw Hill. 2. Computer Systems Architecture – M.Moris Mano, IIIrd Edition, Pearson/PHI Other References:
|
(Bloom’s Taxonomy: BT level 1: Remembering; BT level 2: Understanding; BT level 3: Applying; BT level 4: Analyzing; BT level 5: Evaluating; BT level 6: Creating)
Course Code: LBC0201 | Course Title: Environmental Studies (2 Credits) |
Course Objectives: –
Ø To understand the conceptual framework of environment and it’s interaction with Individuals. Ø To develop an understanding of the interconnectedness of natural systems and human activities. Ø To promote awareness of environmental issues and the impact of technology on the environment. Ø To encourage sustainable practices and responsible decision-making in personal and professional contexts. Ø To foster skills to analyze and solve environmental problems using scientific and technological approaches. Ø To cultivate a sense of ethical responsibility towards environmental conservation and sustainability. |
Course Contents
Unit. | Unit Description | Learning Outcome |
1 | The Multidisciplinary Nature of Environmental Studies: Definition, Scope, and Importance, Need for Public Awareness | Students will be able to achieve BL 1 and 2 (Remembering and Understanding). |
2 | Natural Resources: Introduction, Renewable and Non-Renewable Resources, Role of an Individual in Conservation of Natural Resources, Equitable Use of Resources for Sustainable Lifestyles, Field Work | Students will be able to achieve BL 2 and 3 (Understanding and Applying). |
3 | Ecosystems: Concept of an Ecosystem, Structure and Functions of an Ecosystem; Producers, Consumers and Decomposers; Energy Flow in the Ecosystem, Ecological Succession, Food Chains, Food Webs, and Ecological Pyramids, Ecosystem: Types, Characteristic Features, Structure, and Functions; Field Work | Students will be able to achieve BL 2 and 3 (Understanding and Applying). |
4 | Biodiversity and its Conservation: Introduction: Definition: Genetic, Species, Ecosystem Diversity, Biogeographic Classification of India, Value of Biodiversity: Consumptive, Productive Use, Social, Ethical, Aesthetic and Option Values, Biodiversity at Global, National and Local Levels, India as a Mega Diversity Nation, Hotspots of Biodiversity, Threats to Biodiversity: Habitat Loss, Poaching of Wildlife, Man-Wildlife Conflicts, Endangered and Endemic Species of India, Conservation of Biodiversity: In-Situ and Ex-Situ, Field Work | Students will be able to achieve BL 2, 3, and 4 (Understanding, Applying, and Analyzing). |
5 | Environmental Pollution: Definition, Causes, Effects and Control Measures; Solid Waste Management: Causes, Effects and Control Measures of Urban and Industrial Waste; Role of Individuals in Pollution Prevention; Pollution Case Studies; Disaster Management: Floods, Earthquakes, Cyclones, Landslides; Field Work | Students will be able to achieve BL 3 and 4 (Applying and Analyzing). |
6 | Social Issues and the Environment: From Unsustainable to Sustainable Development, Urban Problems Related to Energy, Water Conservation, Rain Water Harvesting, Watershed Management, Resettlement and Rehabilitation of People, Its Problems and Concerns. Case Studies Environmental Ethics: Issues and Possible Solutions, Climate Change, Global Warming, Acid Rain, Ozone Layer Depletion, Nuclear Accidents and Nuclear Holocaust. Case Studies Wasteland Reclamation, Consumerism and Waste Products, Environment Protection Act, Air (Prevention and Control of Pollution) Act, Water (Prevention and Control of Pollution) Act, Wildlife Protection Act, Forest Conservation Act, Issues Involved in Enforcement of Environmental Legislation; Public Awareness, Field Work | Students will be able to achieve BL 2, 3, and 4 (Understanding, Applying, and Analyzing). |
7 | Human Population and the Environment: Population Growth, Variation Among Nations, Population Explosion – Family Welfare Program, Environmental and Human Health, Human Rights, Value Education, HIV/AIDS, Women and Child Welfare, Role of Information Technology in Environment and Human Health, Field Work | Students will be able to achieve BL 3 and 4 (Applying and Analyzing). |
Textbook References:
Other References:
Monographs for Suggested Case Studies:
|
(Bloom’s Taxonomy: BT level 1: Remembering; BT level 2: Understanding; BT level 3: Applying; BT level 4: Analyzing; BT level 5: Evaluating; BT level 6: Creating)
Course Code: LBC0205 | Course Title:Management Principles(3 Credits) |
Course Objectives: –
Ø To describetheoreticalaspects,processandprinciples,scopeofmanagementanditsapplicationtomodernmanagementpractice. Ø To provide a basic framework to understand the evolution of the concept of management. Ø Ti demonstrates and understand major functions of management with emphasis on planning, organizing, staffing, directing and controlling. Ø To definetherolesandresponsibilitiesofamanagerintheorganization. Ø To illustratetheimportanceofplanning,organizing,staffing, directingandcontrollingin decision-making.
|
Course Contents
Unit | Unit Description | Learning Outcome |
1 | Introduction to Management: Definition, Meaning, Significance, Nature and Purpose of Management, The Evolution of Management Thoughts, Roles of Manager, Scientific Management | Students will be able to understand different concepts of management. (BL 1: Remembering, BL 2: Understanding) |
2 | Planning: Meaning of Planning, Nature, Importance, Types of Plans, Steps in Planning | Students will understand planning and its relevance in management. (BL 2: Understanding, BL 3: Applying) |
3 | Forecasting: Introduction, Determinants, Benefits, Limitations, Techniques, Combining Forecasts, Difficulties in Forecasting Technologies | Students will understand the concept of forecasting in detail. (BL 2: Understanding, BL 3: Applying) |
4 | Organizing: Nature of Organizing, Departmentalization, Organization Levels, Span of Management, Organizational Structure, Process, Principles | Students will understand the concept and process of organizing. (BL 2: Understanding, BL 3: Applying, BL 4: Analyzing) |
5 | Span of Management: Introduction, Impact, Factors, Centralization, Decentralization, Importance | Students will understand the concept of Span of Management, Centralization &Decentralization. (BL 2: Understanding, BL 3: Applying, BL 4: Analyzing) |
6 | Staffing: Definition, Process, Importance, Manpower Planning, System Approach to HRM, Recruitment, Selection, Performance Appraisal | Students will understand basic concepts related to staffing and performance appraisal. (BL 1: Remembering, BL 2: Understanding, BL 3: Applying) |
7 | Directing or Leading: Introduction to Motivation, McGregor’s Theory of X and Y, Maslow’s Hierarchy of Needs Theory, Herzberg’s Motivation-Hygiene Theory, Leadership, Traits, Styles, Communication | Students will learn about the concept of directing in detail. (BL 2: Understanding, BL 3: Applying, BL 4: Analyzing) |
8 | Controlling: Definition, Process, Feedback System, Importance, Major Techniques | Students will learn about the concept of controlling in management. (BL 2: Understanding, BL 3: Applying, BL 4: Analyzing) |
9 | Delegation, Authority & Power: Concept of Delegation, Features, Principles, Advantages, Issues, Types of Authority and Power | Students will understand delegation, authority, and power. (BL 2: Understanding, BL 3: Applying, BL 4: Analyzing) |
Textbook References:
Other References:
|
(Bloom’s Taxonomy: BT level 1: Remembering; BT level 2: Understanding; BT level 3: Applying; BT level 4: Analyzing; BT level 5: Evaluating; BT level 6: Creating)
Course Code: LBC0202 | Course Title:Operating Systems (3 Credits) |
Course Objectives: –
Ø To understand the basic concepts and structure of operating systems. Ø To explore process management, CPU scheduling, and process synchronization. Ø To gain knowledge of memory management techniques and storage management. Ø To learn about file systems, system protection, and I/O systems. Ø To analyze case studies of popular operating systems to understand their design principles and key features. |
Course Contents
Unit | Unit Description | Learning Outcome |
1 | Basics of Operating Systems: Generations, Types, Structure, Services, System Calls, System Boot, System Programs, Protection and Security | Students will be able to achieve BL 1 and 2. |
2 | Process Management: Process Concepts, Process States, Process Control Block | Students will be able to achieve BL 2 and 3. |
3 | CPU Scheduling: Scheduling Criteria, Scheduling Algorithms and their Evaluation, Threads, Threading Issues | Students will be able to achieve BL 2 and 3. |
4 | Process Synchronization: Background, Critical-Section Problem, Peterson’s Solution, Synchronization Hardware, Semaphores, Classic Problems of Synchronization, Monitors | Students will be able to achieve BL 2, 3, and 4. |
5 | Deadlock: System Model, Deadlock Characterization, Deadlock Prevention, Detection and Avoidance, Recovery from Deadlock | Students will be able to achieve BL 2, 3, and 4. |
6 | Memory Management I: Main Memory, Swapping, Contiguous Memory Allocation, Paging, Structure of Page Table, Segmentation | Students will be able to achieve BL 2 and 3. |
7 | Memory Management II: Virtual Memory, Demand Paging, Page Replacement Algorithms, Allocation of Frames, Thrashing | Students will be able to achieve BL 2, 3, and 4. |
8 | Storage Management: Mass-Storage Structure, Disk Structure, Disk Attachment, Disk Scheduling | Students will be able to achieve BL 2 and 3. |
9 | File System Interface: File Concept, Access Methods, Directory Structure, File System Structure, Allocation Methods, Free-Space Management | Students will be able to achieve BL 2, 3, and 4. |
10 | System Protection: Goals, Principles, Domain of Protection, Access Matrix, Access Control | Students will be able to achieve BL 2, 3, and 4. |
11 | I/O Systems: Overview, I/O Hardware, Application I/O Interface, Kernel I/O Subsystem, Transforming I/O Requests to Hardware Operations | Students will be able to achieve BL 2 and 3. |
12 | Case Study of Popular Operating Systems: Windows, Linux, macOS, Key Features, Design Principles | Students will be able to achieve BL 3, 4, and 5. |
Textbook References:
Other References:
|
(Bloom’s Taxonomy: BT level 1: Remembering; BT level 2: Understanding; BT level 3: Applying; BT level 4: Analyzing; BT level 5: Evaluating; BT level 6: Creating)