DS Week 1 C++ Lecture by DR Gaurav
DS Week 1 C++ Lecture by DR Gaurav
Week 1 Lecture/Lab
by
Dr Gaurav Kumar
Asst. Prof, Bennett University
Course Structure
Note: Reading Book/s and Making dedicated DSA Notes are mandatory for all students.
Increase your Imagination and Creativity
C++ Certifications
C++ Essentials – Part 1 (Basics) Channel: Edube Interactive Mode: Self-Study
Level: Beginner Cost: Free Study Time: 42 hours (Recommended: 7h/week)
Class Lectures
First Week Topics
Meet Your
Subject Mentor
Dr Gaurav Kumar
Asst. Professor, SCSET
NSS Program Coordinator, Bennett University
About
Dr Gaurav
3.8 years of research and
Social Entrepreneurship
Experience,
(7.5+ Years of
Volunteering Experience)
About Dr Gaurav
PUBLISHED 9 CONFERENCES
& JOURNALS
42 TRAINING SESSIONS
Computer & Cyber Security
CHAIR OF ACM & IEEE CHAPTER
Year 2013 and 2017
75 + WORKSHOPS AND SEMINARS
ORGANISED
UGC NET AND CSIR JRF
Year 2013
Fun Facts about Dr Gaurav
www.collcom.org
Community Service
means a lot
Cyber Sanskar
Talks in Schools
or Colleges
Social Engineering Research Activities
Community Service,
Cooking Badminton
Teaching & Training
Thank You!
MOBILE EMAIL ADDRESS
+91-8586968801 [email protected]
#include <iostream> The #include is a preprocessor directive used to include files for “C out”
Short form of standard, the std namespace contains the built-in classes
using namespace std; and declared functions, bring scope of identifiers into current scope.
{
cout << "This is my first C++ Program";
return 0; It indicates the exit status of the program
}
Data Structure Lab
c) Compilation Error
the program?
d) I am confused
Correct Answer is c
Assessment Time
10
9
8
7
6
5
4
3
2
1
#include <iostream>
int main() {
std::cout << "This is my first C++ Program";
return -11; }
c) Compilation Error
the program?
d) I am confused
Correct Answer is c
Data Structure Lab
6. Write a C++ program to find a sum of first n natural numbers (where n is defined by user)
Sample Test Case
Sample Input: Enter a positive number:5
Sample Output: Sum = 15 Explanation Sum of first 5 natural numbers is 1+2+3+4+5
7. Understand how computers store and process data in binary format for efficient computation and
data storage. Write a C++ program that converts a decimal number to its binary representation
using loops.
Sample Test Case
Enter a decimal number: 13
Binary representation: 1101
Data Structure Lab
8. Implement a C++ program to calculate Investment Growth with Compound Interest: You want to invest a certain
amount ('a') in a long-term account with a fixed interest rate ('r'). Write a program to calculate the investment's value
over 'n' years and print the growth at each interval. This will help you plan your financial future wisely.
9. Implement a C++ program to find the greatest common divisor (GCD) of two given positive integers 'a' and 'b'
using the Euclidean algorithm with a loop.
10. Create a C++ program for a personal health tracker. Input weight and height to calculate your Body Mass Index
(BMI).
Reference,
using namespace std; Short form of standard, the std namespace contains the built-in classes
and declared functions, bring scope of identifiers into current scope.
int main() Execution begins from main function
{
cout << "This is my first C++ Program";
return 0;
It indicates the exit status of the program
}
Brain Storming
c) Compilation Error
the program?
d) I am confused
Correct Answer is c
KBC Assessment Time
10
9
8
7
6
5
4
3
2
1
#include <iostream>
int main() {
std::cout << "This is my first C++ Program";
return -11; }
#include <iostream>
#define MAX 5 //macro
int main()
{
for (int i = 0; i < MAX; i++)
{
std::cout << i << "\n";
}
return 0;
}
Execution Cycle of C++ Program
KBC Assessment Time
10
9
8
7
6
5
4
3
2
1
#include <iostream>
using namespace std;
int display() {
cout<< "This is my first C++ Program”;
return 0; }
Which one is the a) Print the Output
c) Execution Error
the program?
d) I am confused
Correct Answer is b, c
(Please understand the concept of Compilation and Run time Execution of Program.)
Why Object-Oriented Programing
Why Object-Oriented Programing
Note: This statement is partly true, please research and understand the actual concept behind this.
Characteristics of OOPs
Characteristics of OOPs
Encapsulation
Using access specifiers to stops data from being accessed from the outside world
• Public – Data members & member functions can be accessed from outside the class.
• Private – Data members & member functions can only be accessed from within the class.
• Protected – Data members & member functions can be accessed by the class and its derived classes.
Characteristics of OOPs
Abstraction
Abstraction using Classes - A Class can decide using available access specifiers which data member will be
visible to the outside world and which is not.
Abstraction in Header Files – Usage of pow() method present in cmath header file.
Characteristics of OOPs
Polymorphism
“ +” operator in C++ The same entity (function or object) behaves differently in different
scenarios.
Used in numbers to performs addition
This man represents the object, and his relationships display the ability
of this object to be represented in many forms with totally different
characteristics.
Characteristics of OOPs
Inheritance (Reusability)
Inheritance is a process of obtaining the data members and methods
from one class to another class, plus can have its own is known as
inheritance.
Working of Inheritance
#include <iostream> Inheritance (Reusability)
using namespace std;
class Employee
{
public:
float salary = 60000;
};
int main(void) {
Programmer p1;
cout<<"Salary: "<<p1.salary<<endl;
cout<<"Bonus: "<<p1.bonus<<endl;
return 0;
}
#include <iostream> Inheritance (Reusability)
using namespace std;
class Employee
{
public:
float salary = 60000;
};
int main(void) {
Programmer p1;
cout<<"Salary: "<<p1.salary<<endl;
cout<<"Bonus: "<<p1.bonus<<endl;
return 0;
}
Structure
Correct Answer is B
Assessment Time
int a, *b, **c; a
a=10;
*b **c 30
10
b=&a; b
c=&b; 2000
**c=a + 2*(*b); 2000
cout<<"The value of a is : “<< a;
c
4000
Output: 4000
(A) 10
(B) 20 7000
(C) 30
(D) Error
Correct Answer is C
Returning a Pointer (Assessment Time)
To access the members of a structure using a pointer to that structure, you must use
the → operator as follows
struct_pointer->title;
In Normal Structure
cout<< "Book title :“ << book->title; book.title
Dynamic Memory Allocation
Self Study
• Time Complexity
• Asymptotic Analysis
• Arrays
•
Recursions
• Searching Strategy
Any Queries?
Office: MCub311
Email: [email protected]