Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute C++ Online

cpp

#include <iostream>

using namespace std;

class A
{
    protected: 
    int a;
    public:
    void disp_A()
    {
        a=10;
        cout<<"We are in Class A"<<endl;
    }
    
};
class B : public A
{
    protected: 
    int b;
    public:
    void disp_B()
    {
        disp_A();
        cout<<"We are in Class B"<<a<<endl;
    }
    
};


int main()
{
     B bobj;
     bobj.disp_B();
     
   
   return 0;
}

inheritance-accessibility

cpp

#include <iostream>

using namespace std;
class Base{
    public: void view(){
        cout<<"View Function Call"<<endl;
    }
    protected:
    void viewAll()
    {
        cout<<"viewAll function call"<<endl;
    }
    protected:
    void addStudent(){
        cout<<"addStudent function call";
    }
};
class Student:public Base{
    public:
    Student(){
     cout<<endl<<"Student Constructor"<<endl;   
    }
};
class Teacher:protected Base{
    public:
    Teacher() {
     cout<<endl<<"Teacher Constructor"<<endl;   
    }
    public:
    void view(){
        Base::view();
    }
    public:
    void viewAll(){
        Base::viewAll();
    }
};
class Admin:protected Base{
    public:
    Admin(){
     cout<<endl<<"Admin Constructor"<<endl;   
    }
    public:
    void view(){
        Base::view();
    }
    void viewAll(){
        Base::viewAll();
    }
    void addStudent(){
        Base::addStudent();
    }
};
int main()
{
  Student s;
  s.view();
  //s.viewAll(); // error
  //s.addStudent(); // error
  
  Teacher t;
  t.view();
  t.viewAll();
  //t.addStudent(); //error
  
  Admin a;
  a.view();
  a.viewAll();
  a.addStudent();
   return 0;
}

Compile and Execute C++ Online

cpp

#include <iostream>

using namespace std;

int main()
{
int arr[5] = { 0, 1, 2, 3, 4 };
int *p = arr;
(*p) += 2;
++p;
for(int i = 0; i < 5; ++i) {
cout << arr[i] << endl;
}
}

Compile and Execute C++ Online

cpp

#include<iostream>
void swap(int &a,int &b)
{
    b=a+b;
    a=b-a;
    b=b-a;
}
int main()
{
    int a,b;
    cout<<"enter two numbers to be swapped:";
    cin>>a>>b;
    cout<<"value before swap:"<<endl;
    cout<<"a="<<a;
    cout<<endl;
    cout<<"b="<<b;
    cout<<endl;
    swap(a,b);
    cout<<"value after swap:"<<endl;
    cout<<"value of a:"<<a<<endl;
    cout<<"value of b:"<<b<<endl;
    getch();
    return 0;
}
    
    

Compile and Execute C++ Online

cpp

#include <iostream>

using namespace std;

int main()
{
   cout << "Hello World\n"; 
}

beautiful

cpp

#include <algorithm>

using namespace	std;

class A
{

  int vx,vy;

};

class Util
{
  static bool comparAfctB(const A& a1, const A& a2)
  {
    return b.distance(a1) < b.distance(a2);
  }


  static A b;

};



int main ()
{
  A b;

  Util.b=b;

  vector <A*> v;
  v.push_back(new A);  v.push_back(new A);

  sort (v.begin(), v.end(), Util::ComparAfctB);

}




Asgn.6

cpp

#include <stdio.h> 
#include <limits.h> 
   

#define V 9 
   

int minDistance(int dist[], bool sptSet[]) 
{ 
   
   int min = INT_MAX, min_index; 
   
   for (int v = 0; v < V; v++) 
     if (sptSet[v] == false && dist[v] <= min) 
         min = dist[v], min_index = v; 
   
   return min_index; 
} 
   

int printSolution(int dist[], int n) 
{ 
   printf("Vertex   Distance from Source\n"); 
   for (int i = 0; i < V; i++) 
      printf("%d tt %d\n", i, dist[i]); 
} 
   

void dijkstra(int graph[V][V], int src) 
{ 
     int dist[V];     

   
     bool sptSet[V];  
                     
   
     
     for (int i = 0; i < V; i++) 
        dist[i] = INT_MAX, sptSet[i] = false; 
   
     
     dist[src] = 0; 
   
     
     for (int count = 0; count < V-1; count++) 
     { 
       

       int u = minDistance(dist, sptSet); 
   
       
       sptSet[u] = true; 
   
       
       for (int v = 0; v < V; v++) 
   

         if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX  
                                       && dist[u]+graph[u][v] < dist[v]) 
            dist[v] = dist[u] + graph[u][v]; 
     } 
   
     
     printSolution(dist, V);
} 
   

int main() 
{ 
   
   int graph[V][V] = {{0, 4, 0, 0, 0, 0, 0, 8, 0}, 
                      {4, 0, 8, 0, 0, 0, 0, 11, 0}, 
                      {0, 8, 0, 7, 0, 4, 0, 0, 2}, 
                      {0, 0, 7, 0, 9, 14, 0, 0, 0}, 
                      {0, 0, 0, 9, 0, 10, 0, 0, 0}, 
                      {0, 0, 4, 14, 10, 0, 2, 0, 0}, 
                      {0, 0, 0, 0, 0, 2, 0, 1, 6}, 
                      {8, 11, 0, 0, 0, 0, 1, 0, 7}, 
                      {0, 0, 2, 0, 0, 0, 6, 7, 0} 
                     }; 
   
    dijkstra(graph, 0); 
   
    return 0; 
} 

Compile and Execute C++ Online

cpp

#include <iostream>

using namespace std;

int main()
{
    float number1,number2,sum,average;
   cout << "Enter Two Numbers: ";
   cin >> number1;
   cin >> number2;
   
   sum = number1+number2;
   average = sum/2;
   
   cout << "Sum = " << sum << "\n";
   cout << "Average = " << average << "\n";
   
   return 0;
}

Compile and Execute C++ Online

cpp

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int i, j,k,m,n,t,p;
    float r[m],x[n],A[t][p],alpha_k,check,vector_prod,sum_no1,sum_no2,check_sum,b[n],sum_no;
    cout<<"Enter the dimension of the matrix";
    cin>>n;
    for (i=0;i<n;i++)
        for (j=0;j<n;j++)
        {
            cout<<"Enter "<<i<<"and"<<j<<"th"<<" element";
            cin>>A[i][j];
        }
    for (i=0;i<n;i++)
    {
        cout<<"Enter "<<i<<" th"<<" element of b";
        cin>>b[i];
    }
    
    k=0;
    check=10;
    while (check>=0.001);
    {
    k=k+1;
    //Guess solution 
    for (i=0;i<n;++i)
    {
        x[i]=0;
    }
    //computing the residual vector
    for (i=0;i<n;++i)
    sum_no=0;
    {
        for (j=0;j<n;++j)
        {
            sum_no=sum_no+A[i][j]*x[j];
        }
        r[i]=b[i]-sum_no;
    }
    //Computing the alpha k
    for (i=0;i<n;++i)
    {
    vector_prod=vector_prod+pow(r[i],2);
    sum_no1=0;
    sum_no2=0;
    for (j=0;j<n;++j)
    sum_no1=sum_no1+x[j]*A[j][i];
    sum_no2=sum_no2+sum_no1*x[i];
    }
    alpha_k=vector_prod/sum_no2;
    //Updating the solution
    for (i=0;i<n;++i)
    x[i]=x[i]+alpha_k*r[i];
    //Checking for repetition
    check_sum=0;
    for (i=0;i<n;++i)
    {
        check_sum=check_sum+pow(r[i],2);
    }
    check=sqrt(check_sum);
    }
    
    cout<<"Solution=";
    for (i=0;i<n;i++)
    cout<<x[i];
    return 0;
}

Points of interest 2

cpp

#include <iostream>
#include <vector>

using namespace std;

struct vector3
{
    float x, y, z;

    vector3 operator + (const vector3& v) const;
    vector3 operator - (const vector3& v) const;
    
    float   length() const;
    float   dot(const vector3& v) const;
    vector3 cross(const vector3& v) const;
    vector3 normalize() const;
};

struct Camera
{
    vector3 position;
    vector3 forward, right, up;
};

struct PointOfInterest
{
    vector3 position;
};


PointOfInterest* closestToViewCenter(const Camera& camera,
                                     const std::vector<PointOfInterest>& poi)
{
    












}

int main () {}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.