Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

TASKS You will create a class called Linkage that characterizes the motion of a

ID: 3605775 • Letter: T

Question

TASKS

You will create a class called Linkage that characterizes the motion of a pinned four-bar linkage. Your class must have the following attributes:

Your class must also have the following methods and constructors:

Linkage class constructors

Linkage(double S, double P, double Q, double L) -This is the object constructor that should initialize the objects member values. Member values MUST be provided through console input. The user must be prompted to enter the link lengths from shortest to longest.

Linkage class accessors

double getLongest() – returns length of the longest link

double getP() – returns length of the first intermediate link

double getQ() – returns length of the second intermediate link

double getShortest() – returns length of the shortest link

string Motion() – returns the type of motion (ie, crank rocker, triple rocker, change point)

Linkage class mutators

void setLongest(double L) – sets longest length

void setQ(double Q) – sets first intermediate length

void setP(double P) – sets second intermediate length

void setShortest(double S) – sets shortest length

A Linkage object constructed from a Linkage class exists to characterize motion type. Thus, for the purposes of this class you are required to use the following strings as the return values of the motion accessor.

You must implement the functions for the Linkage class in the file Linkage.cpp and define the class in Linkage.h. The file main.cpp will only be used for testing purposes, no code should be written in main.cpp.

You can determine which of the three types of motion will happen by applying the following formula:

S + L < = > P + Q

If S + L < P + Q, and the input link is the short link, you will have a crank rocker.

If S + L > P + Q, you will have a triple rocker.

If S + L = P + Q, you will have a change-point linkage.

SAMPLE INPUT AND OUTPOUT

Enter the link lengths in descending order from longest to shortest. Units are meters.
> 14.6
> 10.8
> 9.1
> 7.2
> You entered s1:14.6 s2:10.8 s3:9.1 s4:7.2
> Linkage Constructor was called
> Enter in a NEW longest length
> 15.1
> Called setLongest method
> Called getLongest method
> In main: calling getLongest on the link object: 15.1
> Called getShortest method
> In main: calling getShortest on the link object: 7.2
> Called getP method
> In main: calling getP on the link object: 10.8
> Called getQ method
> In main: calling getQ on the link object: 9.1
> Called Motion method
> This pinned four-bar linkage is a triple rocker.

> Linkage Constructor was called
> Creating a new linkage with L,P,Q,S as 50,40,30,20
> Calling Motion() expecting a change-point linkage
> Called Motion method
> This pinned four-bar linkage is a change-point linkage.

> Shortening longest to 45, creating a crank rocker linkage
> Called setLongest method
> Calling Motion() expecting a crank Rocker linkage
> Called Motion method
> This pinned four-bar linkage is a crank rocker.

> Lengthening shortest to 26, creating a triple rocker linkage
> Called setShortest method
> Calling Motion() expecting a triple rocker linkage
> Called Motion method
> This pinned four-bar linkage is a triple rocker.

SAMPLE STARTER CODE

#ifndef LINKAGE_H
#define LINKAGE_H

#include

class Linkage{

public:
//This is the class constructor
Linkage(double L, double P, double Q, double S);
//returns length of the longest link
double getLongest();
//returns length of the first intermediate link
double getP();
//returns length of the second intermediate link
double getQ();
//returns length of the shortest link
double getShortest();
//returns the type of motion (ie, crank rocker, triple rocker, change point)
std::string Motion();

//sets longest length
void setLongest(double L);
//sets first intermediate length
void setP(double P);/** updated      **/
//sets second intermediate length
void setQ(double Q);/** updated      **/
//sets shortest length
void setShortest(double S);

private:
static const std::string triple;
static const std::string crank;
static const std::string change;
double longest_length_L;
double intermediate_length_P;
double second_length_Q;
double shortest_length_S;



};

#endif



//Linkage.cpp is below this comment
#include
#include "Linkage.h"

using namespace std;

const std::string Linkage::triple = "This pinned four-bar linkage is a triple rocker .";
const std::string Linkage::crank = "This pinned four-bar linkage is a crank rocker .";
const std::string Linkage::change = "This pinned four-bar linkage is a change-point linkage.";


Linkage::Linkage(double L, double P, double Q, double S)
{
std::cout << "Linkage Constructor was called" << std::endl;
this->longest_length_L = L;
this->intermediate_length_P = P;
this->second_length_Q = Q;
this->shortest_length_S = S;
}


double Linkage::getLongest()
{
std::cout << "Called getLongest method" << std::endl;
return this->longest_length_L;
}

void Linkage::setLongest(double L)
{
std::cout << "Called setLongest method" << std::endl;
this->longest_length_L = L;

}



/**
*
* main.cpp is below this comment
*
**/
int main(void)
{ /** updated      **/
std::cout << "Enter the link lengths in descending order from longest to shortest. Units are meters." << std::endl;
double s1,s2,s3,s4;
std::cin >> s1;
std::cin >> s2;
std::cin >> s3;
std::cin >> s4;
std::cout << "You entered s1:" << s1 << " s2:"< Linkage link(s1,s2,s3,s4);
std::cout << "Enter in a NEW longest length" << std::endl;
double newLongest;
std::cin >> newLongest;

//pass the new longest to the set method!!
link.setLongest(newLongest);

std::cout << "In main: calling getLongest on the link object: " << link.getLongest() << std::endl;
std::cout << "In main: calling getShortest on the link object: " << link.getShortest() << std::endl;
std::cout << "In main: calling getP on the link object: "<< link.getP() << std::endl;
std::cout << "In main: calling getQ on the link object: "<< link.getQ() << std::endl;
std::cout << link.Motion() << std::endl << std::endl;

Linkage newLink(50, 40, 30, 20);          /** updated        **/
std::cout << "Creating a new linkage with L,P,Q,S as 50,40,30,20" << std::endl;
std::cout << "Calling Motion() expecting a change-point linkage" << std::endl;
std::cout << newLink.Motion() << std::endl << std::endl;

/** updated      **/
std::cout << "Shortening longest to 45, creating a crank rocker linkage" << std::endl;
newLink.setLongest(45);
std::cout << "Calling Motion() expecting a crank Rocker linkage" << std::endl;
std::cout << newLink.Motion() << std::endl << std::endl;

/** updated      **/
std::cout << "Lengthening shortest to 26, creating a triple rocker linkage" << std::endl;
newLink.setShortest(26);
std::cout << "Calling Motion() expecting a triple rocker linkage" << std::endl;
std::cout << newLink.Motion() << std::endl;


return 0;
}

Explanation / Answer

**3. Write a function called zeroSmaller() that is passed two int arguments by reference and then sets the smaller of the two numbers to 0. Write a main() program to exercise this function.*/ #include #include using namespace std; bool zeroSmaller(int& n1, int& n2); void main(void) { cout