C++ Classess Part 1 Date:- 28/08/2026
// Online C++ compiler to run C++ program online
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
class student{
protected:
int aa;
public:
string name;
int age;
// void display(int a=213,int cc,int bb=211){ .. This is wrong
void display(int a=213,int bb=211){
aa=a;
cout<<name<<" "<<age<<endl;
cout<<a<<endl;
cout<<bb<<endl;
}
void ss();
};
void student::ss(){
cout<<"Hello their"<<endl;
}
class a:student{
public:
void ii(int bb){
aa=bb;
cout<<aa<<endl;
}
};
int add(int a,int b){
cout<<a+b<<endl;
return 1;
}
double add(int a,int b,int c){
cout<<a+b+c<<endl;
return 1.1;
}
template <typename t>
t addd(t a,t b){
// cout<<a+b<<endl; // We cannot use cout in it
return a+b;
}
int main() {
// Write C++ code here
// std::cout << "Start small. Ship something.";
student s;
s.name="Gunjan Nayak";
s.age=22;
// s.a=21;
s.display(21);
s.ss();
a b;
// b.aa=12;
b.ii(21);
// b.ss();
cout<<"REFERENCES"<<endl;
int z=12;
int y=21;
int& x=z;
x=y;
// int &zz; // a reference must be initialized
// x=21;
// z=23;
cout<<x<<endl;
cout<<z<<endl;
cout<<addd(12,12)<<endl;
cout<<addd(12.34,3.14)<<endl;
auto greet=[](){
cout<<"Hello Gunjan"<<endl;
};
auto find=[](int a,int b)->int{
return a+b;
};
int xx=21;
auto nn=[xx](){
cout<<xx<<endl;
};
int vv=23;
auto cvt=[&vv](){
vv=231;
};
auto veel=[=](){ // '=' captures everything means every variable.
cout<<vv+xx<<endl;
};
auto capp=[&](){ // '&' captures everything by reference.
vv=37;
};
cout<<find(12,12)<<endl;
greet();
nn();
cvt();
veel();
capp();
cout<<vv<<endl;
vector<int> well={21,33,11,1,9,7,8};
sort(well.begin(),well.end(),[](int a,int b){
return a>b;
});
for(auto i:well){
cout<<i<<endl;
}
return 0;
}
Comments
Post a Comment