sodapdf-converted
sodapdf-converted
int main()
{
std::cout<<"Hello World";
return 0;
}
*/
/*wrp to print student details//
#include <iostream>
using namespace std;
class Student {
private:
int roll_no;
char name[50];
float marks;
public:
// Function to input student details
void inputData() {
cout << "Enter Roll Number: ";
cin >> roll_no;
int main() {
Student s; // Creating an object of Student class
s.inputData(); // Taking input
s.displayData(); // Displaying output
return 0;
}
*/
/*wrp to to demonstrate theinline function//
#include <iostream>
using namespace std;
class operators{
public:
// Inline function to add two numbers
inline int add(int a, int b) {
return a + b;
}
int main() {
operators obj;
return 0;
}*/
/*wrp to demonstrate the static data memebrand static member function//
#include <iostream>
using namespace std;
class Student {
private:
int roll_no;
string name;
static int count; // Static data member (shared by all objects)
public:
// Constructor to initialize student details
Student(string n, int r) {
name = n;
roll_no = r;
count++; // Increment count when a new student object is created
}
int main() {
// Creating static objects
static Student s1("Alice", 101);
static Student s2("Bob", 102);
return 0;
}*/
/*wrp to implements the stuent details//
#include <iostream>
#include <cstring>
using namespace std;
class Student {
private:
int roll_no;
char name[20];
int marks[3];
int total() {
return marks[0] + marks[1] + marks[2];
}
public:
void set_data(int r, const char* n, int m1, int m2, int m3) {
roll_no = r;
strncpy(name, n, 19);
name[19] = ’\0’;
marks[0] = m1;
marks[1] = m2;
marks[2] = m3;
}
int main() {
Student s;
s.set_data(101, "John Doe", 85, 90, 88);
s.display_data();
return 0;
}*/
/*wrp to generate the student id for all the objetsof the class being created//
#include <iostream>
using namespace std;
class Student {
private:
int student_id;
string name;
static int next_id; // Static variable //
public:
// Constructor//
Student(string n) {
name = n;
student_id = next_id;
next_id++;
}
void display() {
cout << "Student ID: " << student_id << ", Name: " << name << endl;
}
};
int main() {
// Creating student objects
Student s1("sriksnth");
Student s2("sanjay");
Student s3("teja");
Student s4("naveen");
Student s5("chethan");
return 0;
}*/
/*wrp to enhance car class from previous practical by making data members private//
#include <iostream>
using namespace std;
class Car {
private:
string brand;
string model;
int year;
double price;
public:
// Setter functions to modify private members
void setBrand(string b)
{ brand = b;
}
void setModel(string m) {
model = m;
}
void setYear(int y)
{ year = y;
}
void setPrice(double p)
{ price = p;
int main() {
Car car1;
return 0;
}*/
/*wrp to demonstrate callby value//
#include <iostream>
using namespace std;
void Value(int x) {
x = x + 10;
cout << "(Call by Value): " << x << endl;
}
int main() {
int a = 5;
Value(a);
cout << "(Original Value): " << a << endl;
return 0;
}*/
/* wrp to demnatrsate the call by address//
#include <iostream>
using namespace std;
int main() {
int a = 5;
Value(&a);
cout << " (Original Value): " << a << endl;
return 0;
}*/
/*wrp to demonstrate the call by reference//
#include <iostream>
using namespace std;
int main() {
int a = 5;
Value(a);
cout << "(Original Value): " << a << endl;
return 0;
}*/
/*wrp to demonstrate this pointer//
#include <iostream>
using namespace std;
class Test {
int x;
public:
void setX(int x) {
this->x = x;
}
void print() {
cout << "Value of x: " << this->x << endl;
}
};
int main() {
Test obj;
obj.setX(10);
obj.print();
return 0;
}*/
/*wrp to demonstrate the friend function//
#include <iostream>
using namespace std;
class Test {
int x;
public:
Test(int x) : x(x) {}
friend void printX(Test &obj); // Friend function declaration
};
int main() {
Test obj(10);
printX(obj);
return 0;
}*/
/*wrp to demonstrate the friend class//
#include <iostream>
using namespace std;
class Test {
int x;
public:
Test(int x) : x(x) {}
friend class FriendClass; // Friend class declaration
};
class FriendClass {
public:
void printX(Test &obj) {
cout << "Value of x: " << obj.x << endl; // Accessing private member
}
};
int main() {
Test obj(10);
FriendClass fc;
fc.printX(obj);
return 0;
}*/
/*wrp to demonstrate the bank acc to using constructors //
#include <iostream>
using namespace std;
class BankAccount {
int accountNumber;
double balance;
public:
// Default Constructor//
BankAccount() {
accountNumber = 0;
balance = 0.0;
cout << "Default Constructor" << endl;
}
// Parameterized Constructor
BankAccount(int accNum, double bal) {
accountNumber = accNum;
balance = bal;
cout << "Parameterized Constructor Called!" << endl;
}
// Destructor
~BankAccount() {
cout << "Destructor Called for Account Number: " << accountNumber << endl;
}
void display() {
cout << "Account Number: " << accountNumber << ", Balance: " << balance << endl;
}
};
int main() {
BankAccount acc1; // Default Constructor
acc1.display();
return 0;
}*/
/* private defoult constructor//
#include <iostream>
using namespace std;
class Test {
Test() {
cout << "Private Default" << endl;
}
public:
static Test createObject() {
return Test(); // Accessing private constructor inside the class
}
};
int main() {
Test obj = Test::createObject(); // static function//
return 0;
}*/
/* defoult constructor//
#include <iostream>
using namespace std;
class Test {
public:
Test() {
cout << "Default Constructor" << endl;
}
};
int main() {
Test obj; // Default Constructor is called
return 0;
}*/
/*Parameterized Constructor//
#include <iostream>
using namespace std;
class Test {
int x;
public:
Test(int val) {
x=val;
cout << "Parameterized Constructor Value: " << x << endl;
}
};
int main() {
Test obj(10); // Parameterized Constructor
return 0;
}*/
/*copy constructor//
#include <iostream>
using namespace std;
class Test {
int x;
public:
Test(int val) : x(val) {}
Test(const Test &obj) { // Copy Constructor
x = obj.x;
cout << "Copy Constructor Value: " << x << endl;
}
void display() {
cout << "Value: " << x << endl;
}
};
int main() {
Test obj1(10);
Test obj2 = obj1; // Copy Constructor
obj2.display();
return 0;
}*/
/* wrp defoult cpy constructor//
#include <iostream>
using namespace std;
class Test {
int x;
public:
Test(int val) : x(val) {}
void display() {
cout << "Value: " << x << endl;
}
};
int main() {
Test obj1(10);
Test obj2 = obj1; // Default Copy Constructor
obj2.display();
return 0;
}*/
/*dynamkic constructor//
#include <iostream>
using namespace std;
class Test {
int *ptr;
public:
Test(int size) { // Dynamic Constructor
ptr = new int[size];
cout << "Dynamic Constructor" << endl;
}
~Test() { // Destructor
delete[] ptr;
cout << "Destructor" << endl;
}
};
int main() {
Test obj(5); // Dynamic Constructor
return 0;
}*/
/*shollow copy vs deep copy
#include <iostream>
using namespace std;
class Test {
int *ptr;
public:
Test(int val) {
ptr = new int(val);
}
// Deep Copy Constructor
Test(const Test &obj) {
ptr = new int(*obj.ptr);
cout << "Deep Copy constructor" << endl;
}
void setValue(int val) {
*ptr = val;
}
void display() {
cout << "Value: " << *ptr << endl;
}
~Test() {
delete ptr;
}
};
int main() {
Test obj1(10);
Test obj2 = obj1; // Deep Copy Constructor
obj2.setValue(20);
obj1.display();
obj2.display();
return 0;
}*/