Suba C++ and Qt
Suba C++ and Qt
&
QT CREATOR
SUBA S M
PROGRAMMING IN MODERN
C++
INTRODUCTION TO
C++
C++ Overview: C++ is a general-purpose programming language derived from C,
designed for system and application programming, emphasizing performance,
efficiency, and flexibility.
Object-Oriented: C++ supports object-oriented programming paradigms, allowing for
the creation of reusable code components called objects, which encapsulate data and
behavior.
Syntax: C++ syntax is similar to C but includes additional features like classes,
templates, and operator overloading, providing more expressive power and abstraction.
Standard Template Library (STL): C++ comes with a rich standard library known as
the STL, providing a set of reusable algorithms and data structures like vectors, lists, and
maps, enhancing productivity and code quality.
Platform Independence: C++ programs can be compiled to run on various platforms,
including Windows, Linux, and macOS, ensuring cross-platform compatibility and
flexibility in deployment.
Arrays in C++
• Syntax
PUSH OPERATION:
Elements can be added to the top of the stack using the push() method.
myStack.push(5);
Pop Operation:
The pop() method removes the top element from the stack.
REFERENCE AND POINTER
Reference Pointer
Reference: Pointer:
A reference variable is a "reference" to A pointer is a variable that stores
an existing variable, and it is created with the memory address of another variable.
the & operator: Pointers allow indirect access to memory
Syntax; locations, enabling manipulation of data and
int x = 10; dynamic memory allocation.
int & ref = x; // ref is a reference to x Syntax;
int x = 10;
int* ptr = &x; // Initializes ptr with the
address of x
CLASSES AND OBJECTS
Classes:
It is a user-defined data type, which holds its own data members and
member functions, which can be accessed and used by creating an instance of that
class
A C++ class is like a blueprint for an object.
Objects:
An object in C++ is an instance of a class.
When class is define, no memory is allocated but when an (object is
created ) memory is allocated.
FUNCTION OVERLOADING
Allows you to define multiple functions with the same name but different parameter lists. this means you can have
multiple functions with the same name, but each function performs a different task based on the parameters it receives.
Example code
#include <iostream>
int add(int a, int b) {
return a + b;}
int add(int a, int b, int c) {
return a + b + c;
}
int main() {
std::cout << "Sum of 5 and 7: " << add(5, 7) << std::endl;
std::cout << "Sum of 3, 4, and 6: " << add(3, 4, 6) << std::endl;
return 0;
ACCESS SPECIFIERS
PUBLIC PRIVATE
• They can be accessed by any code that can see the • They cannot be accessed directly from outside the
class. class.
• Useful for interface methods and attributes. • Helps in hiding implementation details.
▪ Used when you want derived classes to have access but not other classes.
CONSTRUCTOR
TYPES OF CONSTRUCTOR
✓ DEFAULT
✓ PARAMETERISED
✓ COPY
Default Constructor:
Automatically invoked when an object is created without any arguments.
Initializes data members to default values or performs any necessary setup.
Example: MyClass() {}
Parameterized Constructor:
Accepts arguments during object creation to initialize data members.
Allows customization of object initialization based on provided values.
Example: MyClass(int value) { data = value; }
Copy Constructor:
Creates a new object as a copy of an existing object.
Copies data members of the source object to the new object.
Example: MyClass(const MyClass& other) { data = other.data; }
Introduction of QT creator
• QT Designers
• Qt Gui tools
• QT Helps
• Qt Test
QT Designers
• Qt Designer enables you to quickly build the GUI of your main
windows using the predefined Main Window template.
• Once you've created a form based on that template, you'll have
tools to perform the following actions: Creating a main menu.
• Adding and populating toolbars.
QT Gui tools