[go: up one dir, main page]

0% found this document useful (0 votes)
6 views28 pages

Mooc Report

This document is a seminar report on C++ programming submitted by Gaurav Singh as part of his BCA degree requirements at Graphic Era Hill University. It includes an overview of the history of programming languages, an introduction to C++, and various programming concepts such as condition structures, iteration structures, and variable scope. The report also acknowledges the contributions of Saylor Academy and the guidance of Dr. Jitendra Kumar Chaudhary.

Uploaded by

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

Mooc Report

This document is a seminar report on C++ programming submitted by Gaurav Singh as part of his BCA degree requirements at Graphic Era Hill University. It includes an overview of the history of programming languages, an introduction to C++, and various programming concepts such as condition structures, iteration structures, and variable scope. The report also acknowledges the contributions of Saylor Academy and the guidance of Dr. Jitendra Kumar Chaudhary.

Uploaded by

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

A

MOOC based Seminar Report


On
C++ Programming
MOOC https://www.saylor.org/

Submitted in partial fulfillment of the requirement Seminar for the I Semester


BCA
By

Name- GAURAV SINGH


Roll Number- 2471065
Under the Guidance of
Dr. Jitendra Kumar Chaudhary
Assistant professor
School of Computing

School of Computing
GRAPHIC ERA HILL UNIVERSITY BHIMTAL CAMPUS
SATTAL ROAD, P.O. BHOWALI
DISTRICT- NAINITAL-263136
2024 - 2027

1
BHIMTAL CAMPUS

THIS IS TO CERTIFY THAT Mr. GAURAV SINGH HAS SATISFACTORILY


PRESENTED MOOC BASED SEMINAR. THE COURSE OF THE MOOC
REGISTRATION “C++ Programming” IN PARTIAL FULLFILLMENT OF THE
SEMINAR PRESENTATION REQUIREMENT IN II SEMESTER OF BCA DEGREE
COURSE PRESCRIBED BY GRAPHIC ERA HILL UNIVERSITY, BHIMTAL
CAMPUS DURING THE YEAR 2025-2026.

Class Coordinator Concerned Mentor HOD

Dr. Jitendra Chaudhary Dr. Jitendra Chaudhary Dr. S.K.Budhani

Signature Signature Signature

2
BHIMTAL CAMPUS
CERTIFACATE

BHIMTAL CAMPUS

3
CONTENT
S. NO. CONTENTS PER MODULE Page No.
1 History of Programming and Introduction to C++ 06
2 Introduction 06-13
3 Condition and Iteration Structures in C++ 14-21
4 Arrays in C++ 22-23

5 Class Design in C++ 24-26


6 Class Templates in C++ 27-28

ACKNOWLEDGEMENT

I Express my gratitude to Saylor Academy, for coming up with this interesting and thought provoking
course, compiling the best contents and most important working towards changing the words, making
the difference and inspiring us to become the climate saver ourselves , knowledge that I gained will last
a lifetime.

4
I Want to thanks https://www.saylor.org/for broadcasting the content and the very nice user interface.

Many thanks to my institution, Graphic Era Hill University, Bhimtal Campus MOOC Coordinator – Dr.
Jitendra Chaudhary for motivating us to look beyond the syllabus, to take up the opportunity and to
learn as much as we can, as long as we can.

📘 Report on : History of Programming and Introduction to C++


👤 Student Name: Gaurav Singh

🎓 Course: C++ Programming (Saylor Academy)

📚 Module: 1 – History of Programming and Introduction to C++

📅 Date: [14-may-2025]

5
📝 1 Introduction

In today’s technology-driven world, programming languages play a crucial role in developing software
applications, websites, operating systems, and much more. C++ is one of the most widely used
programming languages, known for its power, flexibility, and performance. This report presents an
overview of the history of programming languages and an introduction to C++, as discussed in Module 1
of the Saylor Academy C++ course.

📜 History of Programming Languages

The evolution of programming languages began in the early 19th century and has advanced significantly
over the decades.

🔹 Early Beginnings

 Charles Babbage and Ada Lovelace (1830s):


Ada Lovelace is considered the first programmer for her work on Babbage’s Analytical Engine.
She wrote the first algorithm intended for machine processing.

 1940s – Assembly Language:


The first computers used machine code (binary) and later assembly language, which used
symbolic names for operations and memory locations.

🔹 High-Level Languages

🔹The Birth of C++

 1980s – C++:
Developed by Bjarne Stroustrup, C++ was created as an extension of C. It added object-oriented
programming (OOP) features such as classes and inheritance. This allowed for better data
abstraction, code reuse, and modularity.

💻 1.1. Introduction to C++

C++ is a general-purpose programming language that supports both procedural and object-oriented
programming. It is widely used for system/software development, game development, drivers, client-
server applications, and embedded firmware.

✨ Features of C++

 Object-Oriented Programming: C++ supports OOP concepts such as classes, objects,


inheritance, polymorphism, and encapsulation.

 Low-Level Manipulation: Allows direct manipulation of hardware and memory.


6
🔧 Structure of a C++ Program

A basic C++ program includes:

#include <iostream>

using namespace std;

int main() {

cout << "Hello, world!";

return 0;

 #include <iostream> – Includes the input/output stream library.

 using namespace std; – Allows use of standard library functions without prefix.

 main() – Entry point of every C++ program.

 cout – Used to display output.

🎯 Importance of Learning C++

Learning C++ provides a solid foundation in computer programming. It helps understand fundamental
programming concepts that apply to many other languages. It is also essential for competitive
programming, system-level development, and software engineering.

 💼 Job Opportunities: Many tech companies require C++ developers for high-performance
applications.

 🧠 Understanding of OOP: C++ is an excellent language to learn object-oriented programming.

 🧱 Base for Advanced Languages: Languages like Java, C#, and even Python borrow concepts
from C++.

1.2 How to Compile and Run a C++ Program on Ubuntu Linux.

📝 Introduction

7
Ubuntu is one of the most popular Linux distributions for programmers. It offers a powerful
environment for C++ development using the GNU Compiler Collection (GCC). This report provides a
simple guide to writing, compiling, and running a C++ program on Ubuntu.

⚙️Installing the C++ Compiler (g++)

Before compiling any program, ensure that g++, the GNU C++ compiler, is installed on your system.

📄 Writing a C++ Program

You can use any text editor such as nano, vim, gedit, or Visual Studio Code to write your C++ code.

✍️Example: Creating a file using nano

bash

nano hello.cpp

💡 Sample C++ Code

#include <iostream>

using namespace std;

int main() {

cout << "Hello, world!" << endl;

return 0;

▶️Running the Program

To run the compiled program, enter:

bash

./hello

✅ Output

Hello, world!

This confirms that your program compiled and ran successfully.


8
💻1.3 Simple C++ Commands

📝 Introduction

C++ programs are built using basic commands for input, output, variables, and control structures. These
commands form the core of all beginner-level C++ programming.

🧱 Basic Program Structure

#include <iostream>

using namespace std;

int main() {

return 0;

 #include <iostream>: Enables input/output.

 main(): Starting point of the program.

Output with cout

cout << "Hello, world!" << endl;

Prints text to the screen.

⌨️Input with cin

int age;

cin >> age;

Takes input from the user.

🔁 Loops and Conditions

9
if (age >= 18) {

cout << "Adult";

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

cout << i;

Use if, for, and while for program logic and repetition.

📦 Variable Types

int x = 10;

float temp = 36.5;

char grade = 'A';

string name = "Ali";

Use appropriate types for different data.

🔢1.4 Variables, Data Types, and Constants

📦 Variables

A variable is a named space in memory to store data that can change during program execution.

int age = 20;

float price = 49.99;

string name = "Ali";

🧾 Data Types

C++ supports various built-in data types:

10
Type Description Example

int Integer values int x = 10;

float Decimal numbers float y = 5.75;

double Larger decimal values double z = 9.99;

char Single character char grade = 'A';

bool Boolean (true/false) bool passed = true;

string Text (needs #include <string>) string name = "Ali";

🔒 Constants

Constants are variables whose values do not change once defined.

const float PI = 3.14;

 Declared using const keyword.

 Must be initialized at the time of declaration.

Benefits of using constants:

 Prevent accidental changes.

 Make code easier to read and maintain.

📥1.5 Basic Input and Output in C++

Output with cout

The cout (character output) stream is used to display information to the user.

cout << "Hello, world!" << endl;

 << is the insertion operator, used to send data to the output stream.

 endl is used to end the line and add a newline character.

📌 Example:

cout << "Enter your name: ";


11
cout << "Hello, " << name << "!" << endl;

⌨️Input with cin

The cin (character input) stream is used to accept input from the user.

int age;

cin >> age;

 >> is the extraction operator, used to take data from the input stream and store it in a variable.

📌 Example:

int age;

cout << "Enter your age: ";

cin >> age;

cout << "You entered: " << age << endl;

➗ 1.6 Arithmetic Operators in C++

➕ Addition: +

Used to add two numbers.

int sum = 10 + 5; // sum = 15

➖ Subtraction: -

Used to subtract one number from another.

int difference = 10 - 5; // difference = 5

✖️Multiplication: *

Used to multiply two numbers.

int product = 10 * 5; // product = 50

12
➗ Division: /

Used to divide one number by another. For integer division, the result will be an integer.

int quotient = 10 / 2; // quotient = 5

For floating-point numbers:

float quotient = 10.0 / 3.0; // quotient = 3.3333

🔢 Modulus: %

Used to find the remainder of a division operation.

int remainder = 10 % 3; // remainder =

🔄Module 2- Condition and Iteration Structures in C++

🔍 Condition Structures

Condition structures in C++ allow the program to execute different code depending on whether a
specific condition is true or false. The most common condition structures are if, else, and else if.

if Statement

The if statement checks if a condition is true. If the condition is true, the block of code inside the if
statement is executed.

if (age >= 18) {

cout << "You are an adult." << endl;

else Statement

13
The else statement is used in conjunction with if to provide an alternative action when the condition is
false.

if (age >= 18) {

cout << "You are an adult." << endl;

} else {

cout << "You are a minor." << endl;

else if Statement

The else if statement allows you to check multiple conditions.

if (age > 18) {

cout << "You are an adult." << endl;

} else if (age == 18) {

cout << "You just became an adult!" << endl;

} else {

cout << "You are a minor." << endl;

🔁 Iteration Structures (Loops)

Iteration structures are used to repeatedly execute a block of code multiple times. C++ supports several
types of loops:

for Loop

The for loop is used when the number of iterations is known beforehand.

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

cout << i << " ";

while Loop

The while loop continues executing as long as the specified condition is true.
14
int i = 0;

while (i < 5) {

cout << i << " ";

i++;

do...while Loop

The do...while loop guarantees at least one iteration, even if the condition is false, as it checks the
condition after the loop executes.

int i = 0;

do {

cout << i << " ";

i++;

} while (i < 5);

🔍2.2 Testing and Debugging in C++

🔧 Testing in C++

Testing ensures that the program produces the correct output and behaves as expected. It typically
involves the following steps:

1. Unit Testing: Testing individual functions or components of the program.

2. Integration Testing: Ensuring that different parts of the program work together as expected.

3. System Testing: Testing the entire program to verify that it works under various scenarios.

🐞 Debugging in C++

Debugging involves identifying and fixing errors in the code. Errors can be categorized as:

1. Syntax Errors: Mistakes in the structure of the program (e.g., missing semicolons, incorrect
function names).

15
2. Runtime Errors: Errors that occur while the program is running, such as division by zero or
accessing out-of-bounds arrays.

3. Logical Errors: Errors that result in incorrect output, even though the program runs without
crashing.

Common Debugging Techniques:

 Print Statements: Inserting cout statements in the code to print variable values and track
program flow.

int result = add(3, 5);

cout << "The result is: " << result << endl;

Using a Debugger (GDB): The GNU Debugger (GDB) is a powerful tool that allows you to step
through the program line by line, set breakpoints, and inspect variables.

bash

g++ -g my_program.cpp -o my_program

IDE Debuggers: Integrated Development Environments (IDEs) like Visual Studio or Code::Blocks
come with built-in debuggers, which provide graphical interfaces for stepping through code, setting
breakpoints, and inspecting variables.

🔒2.3 The Scope of Variables in a Simple Function

📝 Introduction

In C++, the scope of a variable refers to the part of the program where the variable is accessible.
Variables can be declared inside functions (local variables) or outside functions (global variables).
Understanding variable scope is crucial to avoid errors related to variable visibility and lifetime. In this
section, we explore the scope of variables within a simple function.

📦 Local Variables

Local variables are declared within a function and can only be accessed inside that function. Once the
function execution ends, the local variable is destroyed.

Example of Local Variables:

#include <iostream>
16
using namespace std;

void greet() {

string name = "Alice";

cout << "Hello, " << name << "!" << endl;

int main() {

greet();

/cout << name;

return 0;

🌍 Global Variables

Global variables are declared outside of all functions, and they are accessible throughout the program.
However, they should be used with caution because they can be modified by any function, which may
lead to unintentional side effects.

🔄 Function Scope and Lifetime

 Scope: Refers to the region of the program where a variable can be accessed.

 Lifetime: Refers to the period during which a variable exists in memory.

For example, local variables have a limited lifetime (exist only during the function call), while global
variables have a global lifetime (exist for the entire program runtime).

🔑 Function Parameters and Scope

Function parameters are also local variables. They are scoped only within the function they are passed
into.

#include <iostream>

17
using namespace std;

void display(int number)

cout << "The number is: " << number << endl;

int main() {

display(5);

return 0;

🔄2.4 Arguments Passed by Value and by Reference

📦 Passing Arguments by Value

When an argument is passed by value, a copy of the argument is made and passed to the function. The
function works with this copy, so any changes made to the parameter inside the function do not affect
the original variable.

 Explanation: In this example, the variable number is passed by value to the modifyValue()
function. The function modifies the copy of number, but the original variable number in main()
remains unchanged.

🔗 Passing Arguments by Reference

When an argument is passed by reference, the function operates directly on the original variable,
meaning changes to the parameter will affect the original variable. This is done by using the reference
operator (&).

📚 2.5 Functions of the string Class in C++


Functions of the string Class in C++

1. length() / size()
Returns the number of characters in the string.

18
string str = "Hello";

cout << str.length(); // Output: 5

2. empty()
Checks if the string is empty.

string str = "";

cout << str.empty(); // Output: 1 (true)

3. append() / +=
Adds characters or a string to the end.

string str = "Hello";

str.append(" World");

str += "!";

cout << str; // Output: Hello World!

4. insert()
Inserts characters at a specific position.

string str = "Hello";

str.insert(5, ", World");

cout << str; // Output: Hello, World

5. erase()
Removes characters from the string.

string str = "Hello, World!";

str.erase(5, 7); // Removes ", World"

cout << str; // Output: Hello!

6. find()
Finds the first occurrence of a substring.

string str = "Hello, World!";

size_t pos = str.find("World");

cout << pos; // Output: 7

19
7. substr()
Returns a substring from a given position.

string str = "Hello, World!";

string sub = str.substr(7, 5); // Extracts "World"

cout << sub; // Output: World

8. compare()
Compares two strings lexicographically.

string str1 = "apple";

string str2 = "banana";

cout << str1.compare(str2); // Output: -1

9. transform()
Converts string to upper or lower case.

transform(str.begin(), str.end(), str.begin(), ::toupper);

cout << str; // Output: HELLO

10. stoi()
Converts a string to an integer.

string str = "1234";

int num = stoi(str);

cout << num; // Output: 1234

11. to_string()
Converts a number to a string.

int num = 1234;

string str = to_string(num);

cout << str; // Output: 1234

20
Module 3- Arrays in C++

📦 Declaring an Array

To declare an array, specify the type of its elements and the number of elements it will hold.

int arr[5]; // Array of 5 integers

 Here, arr is an integer array capable of storing 5 elements. The array indices range from 0 to 4.

🔢 Initializing an Array

You can initialize an array at the time of declaration.

int arr[5] = {1, 2, 3, 4, 5}; // Initialize with specific values

If fewer values are provided than the size of the array, the remaining elements are initialized to 0.

📚3.1 Structures, Unions, and Enumerations in C++

Declaring a Structure:

To define a structure, you use the struct keyword:

struct Student {
21
string name;

int age;

float grade;

};

Here, Student is a structure with three members: name (string), age (integer), and grade (float).

Structure Initialization:

Structures can be initialized at the time of declaration:

Student s2 = {"Bob", 22, 92.5};

🔧 Unions in C++

Declaring a Union:

To define a union, you use the union keyword:

union Data {

int intVal;

float floatVal;

char charVal;

};

Here, Data is a union with three members: intVal, floatVal, and charVal. All members share the same
memory location.

Using a Union:

Accessing members is done in the same way as structures, using the dot (.) operator. However,
remember that only one member can store a value at a time:

Data data;

data.intVal = 10;

cout << "Integer: " << data.intVal << endl;

Union Size:
22
The size of a union is the size of its largest member because all members share the same space:

cout << sizeof(Data); // Output: Size of the largest member (int, float, or char)

🔢 Enumerations in C++

An enumeration (enum) is a user-defined data type that consists of integral constants. It allows you to
define a set of named values, which makes the code more readable and maintainable.

📚Module 4- Class Design in C++

A class is a blueprint for creating objects. It combines data members (attributes) and member
functions (behaviors) into a single unit.

 Class Syntax:

class ClassName {

// Data members

// Member functions

};

 Access Specifiers:

o public: Accessible from outside.

o private: Accessible only within the class.

 Constructor: Initializes objects when created.

ClassName() { // Initialization code }

 Destructor: Cleans up when an object is destroyed.

~ClassName() { // Cleanup code }

 Creating Objects:
23
ClassName obj; // Create an object

4.1 Inheritance in C++

Inheritance allows a derived class to inherit properties and behaviors (data members and member
functions) from a base class. This promotes code reuse.

 Syntax:

class DerivedClass : accessSpecifier BaseClass {

// Derived class members

};

 Access Specifiers:

o public: Members of the base class are accessible in the derived class.

o protected: Base class members are accessible only within derived classes.

o private: Base class members are not directly accessible in the derived class.

4.2 Polymorphism in C++

Polymorphism allows objects of different classes to be treated as objects of a common base class,
enabling dynamic method invocation.

Types of Polymorphism:

1. Compile-time (Static) Polymorphism:

o Achieved via function overloading and operator overloading.

class Print {

public:

void display(int i) { cout << i; }

void display(string s) { cout << s; }

};

2. Run-time (Dynamic) Polymorphism:

o Achieved using virtual functions and function overriding.

class Animal {

public:
24
virtual void sound() { cout << "Animal sound"; }

};

class Dog : public Animal {

public:

void sound() override { cout << "Bark"; }

};

int main() {

Animal* animal = new Dog();

animal->sound();

25
Module 5- Class Templates in C++

A class template allows you to define a class that can work with any data type.

Syntax:

template <typename T> class MyClass {

public:

T value;

MyClass(T val) : value(val) {}

T getValue() { return value; }

};

Function Templates in C++

A function template allows you to write a function that can work with any data type.

Syntax:

template <typename T>

T add(T a, T b) {

26
return a + b;

5.1 File Input/Output in C++

C++ provides file handling capabilities through the fstream library, which allows reading from and
writing to files.

1. Include the fstream Library

#include <fstream>

2. Opening a File

 Input File (Reading): Use ifstream.

 Output File (Writing): Use ofstream.

 Both Input and Output: Use fstream.

ifstream inFile("input.txt"); // Open for reading

ofstream outFile("output.txt"); // Open for writing

3. Writing to a File

ofstream outFile("output.txt");

outFile << "Hello, File!" << endl; // Writing data to file

outFile.close(); // Close the file

4. Reading from a File

ifstream inFile("input.txt");

string line;

while (getline(inFile, line)) {

cout << line << endl; // Print each line from file

inFile.close(); // Close the file

5.3 Exception Handling in C++

27
C++ provides a mechanism to handle runtime errors using exception handling with the try, throw, and
catch keywords.

1. Syntax:

 try block: Code that may throw an exception.

 throw keyword: Used to throw an exception.

 catch block: Handles the exception thrown.

References:
1. Saylor Academy C++ Course:

o As you completed the C++ course from Saylor, you can revisit the official course
material to check for further explanations and examples on exception handling.

o Saylor Academy C++ - Saylor’s free courses, including C++ tutorials.

2. C++ Documentation:

o C++ Exception Handling Overview - Official C++ reference for exception handling.

o Learn C++ Exception Handling (GeeksforGeeks) - A great article for understanding


exception handling in C++.

28

You might also like