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;

int main()
{
   cout << "Hello World" << endl; 
   int i = 0;
   i++;
   return 0;
}

Compile and Execute C++ Online

cpp

#include <iostream>
#include <math.h>
#define pi 3.141592

using namespace std;

int main()
{
    float p = 15.0/7.0;
    cout<<"primera operacion: la division de 15 entre 7 es: "<<p<<endl;
    
    int s = 12%5;
    cout<<"segunda operacion: residuo de 12 dividido 5 es: "<<s<<endl;
    
    int t = 3-(4*6);
    cout<<"tercera operacion: la resta del producto de 4 y 6 es: "<<t<<endl;
    
    bool c = 7>4&&4<8;
    cout<<"cuarta operacion: el valor lógico de 7 mayor que 4 y 4 menor de 8 es: "<<c<<endl;
    
    float q = cbrt(1331);
    cout<<"quinta operacion: la raiz cubica de 1331 es: "<<q<<endl;
    
    int x = (2*15)-7;
    cout<<"sexta operacion: el duplo de 15 disminuido en 7 es: "<<x<<endl;
    
    float m,n;
    m = (2.0*3.141592)/6.0;
    n = sin(m);
    cout<<"septima operacion: el seno de 2 veces pi sobre 6 es: "<<t<<endl;
    
    
    
   system("pause");
   return 0;
}

Compile and Execute C++ Online

cpp

#include <iostream>

using namespace std;

int main()
{
   cout << "Hello World" << endl; 
   
   return 0;
}

CPP Assignment 1 - Q2

cpp

#include <iostream>
using namespace std;

int main ()

{
int speed, time, distance;

speed = 20;
time = 10;
distance = speed * time;

cout << "The distance is " << distance << endl;
return 0;
}

Compile and Execute C++ Online

cpp

 // John Pettway, J00589113, 9/12/17, Assign2
 // Assignment 2, Program to enter and calc avg of 5 test scores then display result to screen

 #include <iostream>
 #include <iomanip>

 using namespace std;

 int main()
 {
 cout << "1) My name is: John Pettway" << endl;
 cout << "2) My Jag# is: J00589113" << endl;
 cout << "3) The last 4 digits of my Jag# is: 9113" << endl;

 // Calculate 5 Test Scores
 double testScore1;
 double testScore2;
 double testScore3;
 double testScore4;
 double testScore5;

 cout << "Enter test score 1: ";
 cin >> testScore1;
 cout << endl;

 cout << "Enter test score 2: ";
 cin >> testScore2;
 cout << endl;

 cout << "Enter test score 3: ";
 cin >> testScore3;
 cout << endl;

 cout << "Enter test score 4: ";
 cin >> testScore4;
 cout << endl;

 cout << "Enter test score 5: ";
 cin >> testScore5;
 cout << endl;

 cout << "Average test score: " << (testScore1+testScore2+testScore3+testScore4+testScore5)/5
<< endl;
 cout << endl;
 return 0;
 }

norberto

cpp

#include <iostream>

using namespace std;

int main()
{
   cout << "Hello World" << endl; 
   
   return 0;
}

Compile and Execute C++ Online

cpp

//Name, Jag#, Date, File Name
//Purpose of Program


#include <iostream>

using namespace std;

int main()
{
   cout << "Hello World" << endl; 
   cout << "1) My name is: John Pettway" << endl;
 cout << "2) My Jag# is: J00589113" << endl;
 cout << "3) The last 4 digits of my Jag# is: 9113" << endl;
 cout << "4) My major is: Electrical Engineering" << endl;
 cout << "5) I am a Sophmore" << endl;
  cout << "6) My hometown is: Safford, Al." << endl;
 cout << "7) An application that impresses me is: Square Register" << endl;
   return 0;
}

Compile and Execute C++ Online

cpp

// Allan Johnson, J00551887, 9/12/17, Assignment 2
 // Assignment 2, Program to enter and calc avg of 5 test scores then display //result to screen

 #include <iostream>
 #include <iomanip>

 using namespace std;

 int main()
 {
 // Attention CIS210 Students: Replace SouthPaw’s information with your own name/jag#
 cout << "1) My name is: Allan Johnson" << endl;
 cout << "2) My Jag# is: J00551887" << endl;
 cout << "3) The last 4 digits of my Jag# is: 1887" << endl;

 // Calculate 5 Test Scores
 double testScore1;
 double testScore2;
 double testScore3;
 double testScore4;
 double testScore5;

 cout << "Enter test score 1: 70";
 cin >> testScore1;
 cout << endl;

 cout << "Enter test score 2: 97.5";
 cin >> testScore2;
 cout << endl;

 cout << "Enter test score 3: 100";
 cin >> testScore3;
 cout << endl;

 cout << "Enter test score 4: 80";
 cin >> testScore4;
 cout << endl;

 cout << "Enter test score 5: 64.5";
 cin >> testScore5;
 cout << endl;

 cout << "Average test score: 82.4" << (70+97.5+100+80+64.5)/5
<< endl;
 cout << endl;

 // when using Visual Studio, use the system/pause command to display the results of your
 // system("pause");
 return 0;
 }

LRU Cache

cpp

#include <iostream>

using namespace std;

typedef struct {
    int key;
    int val;
} elem;
 
class LRUCache{
public:
    elem *arr; 
    int sz;  // total number of elements in the list currently.
    int cap;
 
    LRUCache(int capacity) {
        arr = new elem[capacity];
        sz = 0;
        cap = capacity;
    }
 
    /* move the used element to the end of list */
    void adjust(int a) {
        if (a == sz - 1) {
            return ;
        }
        elem cur = arr[a]; 
        for (int i = a; i < sz - 1; i ++) {
            arr[i] = arr[i + 1]; // move others 1 pos left
        }
        arr[sz - 1] = cur; // move to the end
    }
 
    int get(int key) {
        for (int i = 0; i < sz; i ++) {
            if (arr[i].key == key) {
                int a = arr[i].val;
                adjust(i);
                return a; // existent key
            }
        }
        return -1;
    }
 
    void set(int key, int value) {
        for (int i = 0; i < sz; i ++) {
            if (arr[i].key == key) { // existent
                arr[i].val = value;
                adjust(i);
                return;
            }
        }
        if (sz == cap) { // check if reach the capacity
            for (int i = 0; i < sz - 1; i ++) {
                arr[i] = arr[i + 1]; // delete the least used element
            }
            arr[sz - 1].key = key;
            arr[sz - 1].val = value;
        } else {
            arr[sz].key = key;
            arr[sz].val = value;            
            sz ++; // increase the size
        }
    }
};


int main() {
	int x=10;
	int y=25;
	int z=x+y;
	int i, j;
	
	LRUCache cache(3); //5 elements cache.
	cache.set(1, 10);
	cache.set(2, 20);
	cache.set(3, 30);
	cout << "get(2)=" << cache.get(2) << "\n";
	cout << "get(3)=" << cache.get(3) << "\n";
	cache.set(4, 40);
	cout << "get(1)=" << cache.get(1) << "\n";
	
	cout << "cacah content: ";
	for (i=0; i< cache.cap; i++)
	    cout << cache.arr[i].val << " ";
	cout << "\n";
	
	cache.set(5, 50);
	
	cout << "get(2)=" << cache.get(2) << "\n";
	cout << "cacah content: ";
	for (i=0; i< cache.cap; i++)
	    cout << cache.arr[i].val << " ";
	cout << "\n";
		
}

Compile and Execute C++ Online

cpp

#include <iostream>

using namespace std;

template<typename T> void Swap(T &a, T &b)
{
    T temp=a;
    a=b;
    b=temp;
}
 
 int main()
 {
     int n1 = 100 , n2 = 200;
     Swap(n1, n2);
     
     float n3 = 12.3, n4 = 15.3;
     Swap(n3, n4);
     
     cout << "n1="<< n1<<","<<"n2="<<n2<<endl;
     cout << "n3="<< n3 <<","<<"n4=" <<n4<<endl;
     return 0;
 }

Advertisements
Loading...

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