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

Konstruktor zur Typumwandlung

cpp

#include <iostream>

class Employee {
public:
    explicit Employee(size_t ID=11, size_t Age=22) : mID{ID}, mAge{Age} {
    }
    
    size_t getID();
    size_t getAge();
    
private:
    size_t mID;
    size_t mAge;
};


size_t Employee::getID() {
    return mID;
}
size_t Employee::getAge() {
    return mAge;
}


void foo(Employee e){
    std::cout<<"ID="<<e.getID()<<" Age="<<e.getAge()<<std::endl;
}


int main() {
    Employee e1;
    Employee e2{5, 6};
    Employee e3{5};
    std::cout<<"ID="<<e1.getID()<<" Age="<<e1.getAge()<<std::endl;
    std::cout<<"ID="<<e2.getID()<<" Age="<<e2.getAge()<<std::endl;
    std::cout<<"ID="<<e3.getID()<<" Age="<<e3.getAge()<<std::endl;
    foo(666);
    
    return 0;
}

0444

cpp


Newton Method

cpp

#include <iostream>
#include <cmath>
#include <functional>

using namespace std;

using ld = long double;
using Fx = function<ld(ld)>;

constexpr ld Eps = 0.001F;

struct Segment
{
    ld a;
    ld b;
    ld x;

    Segment(ld x1, ld x2)
    {
        a = x1;
        b = x2;
        x = (a + b)/2.;
    }
};

ld fxsRoot(Fx fx, Segment seg)
{
    ld mid;
    ld dx;

    if (!fx(seg.a)) return seg.a;
    if (!fx(seg.b)) return seg.b;

    dx = seg.b - seg.a;

    while (dx > Eps)
    {
        dx /= 2;
        mid = seg.a + dx;

        if (fx(seg.a)*fx(mid) < 0)
            seg.b = mid;
        else
            seg.a = mid;
    }

    return mid;

}

int main()
{
   Fx fx = [](ld x)
   {
       return x*x - 4;
   };
   
   cout << fxsRoot(fx, Segment(0, 4)) << endl; 
   
   return 0;
}

Leblanc_miles_per_gallon.cpp

cpp

//miles_per_gallon_leblanc.cpp
//austin leblanc
//csci 1933 m02
//program #5
//due date 9/11/17
//program description-calculating miles per gallon
#include <iostream>

using namespace std;

int main()
{
  double gallons = 12, miles = 350;
  double MPG = miles/gallons;
  cout << "A car that holds " << gallons << " gallons of gasoline and \n"
  << "travels " << miles << " before refueling \n"
  << "gets " << MPG << " MPG \n\n";
  
  
  
   return 0;
}

Compile and Execute C++ Online

cpp

#include <iostream>

using namespace std;

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

Boleware_Miles_per_Gallon

cpp

// Boleware_Miles_per_Gallon
// Michael Boleware
// CSCI-1933-M02
// 9-11-17
// This programs calculates miles per gallon

#include <iostream>
using namespace std; 

int main()
{
    float milesDriven = 375.0, gallonsUsed = 15.0;
    float milesPerGallon = milesDriven/gallonsUsed;
    
    cout << "A car drives " << milesDriven << " miles and uses ";
    cout << gallonsUsed << " gallons. The car gets " << milesPerGallon;
    cout << " miles per gallon.";
    
    return 0;
}

2.19

cpp

#include <iostream>
#include <vector>

using namespace std;

/**
* Cubic maximum contiguous subsequence sum algorithm.
*/
class Seque{
    public:
        int * maxSubSum1( const vector<int> & a )
        {
            for( int i = 0; i < a.size( ); ++i )
                for( int j = i; j < a.size( ); ++j )
                {
                    int thisSum = 0;
                    for( int k = i; k <= j; ++k )
                        thisSum = a[ k ];
                    if( thisSum > maxSum[0] )
                        maxSum[0] = thisSum;
                }
            maxSum[1] = a.size();
            return maxSum;
        }
    
    private:
        int maxSum[2];
    
};

int main()
{
    Seque mySeque;
    vector<int> seq = { 5, 13, 18, 39 };
    cout << endl;
    int *val;
    val = mySeque.maxSubSum1(seq); 
    cout << "Maximum subsequence: " << *(val + 0) << endl; 
    cout << "Indices: 0 - " << *(val + 1) << endl;
    return 0;
}

SERGIO

cpp

#include <iostream>

using namespace std;

 
 int N1,N2,N3,C1;
 
  C1=0;
 
  N3=0;
 
 cout<<"ingrese un valor para la tabla"<<endl;cin>>N1;
 
 cout<<"hasta que tabla quiere?"<<cin>>N2;
 
 C1=N1*C1;
 
 cout <<N1<<"X"<<C1<<"="<<C1<<endl;
 
  return 0;

}

Assignment 02

cpp

// Gregory Cochran, J00616801, D8/28/2017, Assignment 02
 // 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: Gregory Cochran" << endl;
 cout << "2) My Jag# is: J00616801" << endl;
 cout << "3) The last 4 digits of my Jag# is: 6801" << 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: " << (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 you program
 // system("pause");
 return 0;
}

Compile and Execute C++ Online

cpp

// Gregory Cochran, J00616801, D8/28/2017, Assignment 02
 // 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: Gregory Cochran" << endl;
 cout << "2) My Jag# is: J00616801" << endl;
 cout << "3) The last 4 digits of my Jag# is: 6801" << 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;

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

Advertisements
Loading...

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