Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Getting multiple definition errors. Can anyone debug/fix or assist? Thanks! (C++/CLion) linkage.h file: #ifndef LINKAGE_H #define LINKAGE_H #include using namespace std; // class Linkage definition

Getting multiple definition errors. Can anyone debug/fix or assist? Thanks! (C++/CLion)

linkage.h file:

#ifndef LINKAGE_H #define LINKAGE_H #include  using namespace std; // class Linkage definition 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: // Data member to store data  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; };// End of class  #endif

linkage.cpp file:

#include  #include  // Includes header file Linkage.h #include "Linkage.h" using namespace std; // Assigns string data to the member 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."; // Parameterized constructor Linkage::Linkage(double L, double P, double Q, double S) { std::cout << "Linkage Constructor was called" << std::endl; // Assigns parameter data to data member of the class  this->longest_length_L = L; this->intermediate_length_P = P; this->second_length_Q = Q; this->shortest_length_S = S; }// End of constructor  // Returns length of the longest link double Linkage::getLongest() { std::cout << "Called getLongest method" << std::endl; return this->longest_length_L; }// End of function  // Sets longest length void Linkage::setLongest(double L) { std::cout << "Called setLongest method" << std::endl; this->longest_length_L = L; }// End of function  // Returns length of the first intermediate link double Linkage::getP() { std::cout << "Called getP method" << std::endl; return this -> intermediate_length_P; }// End of function  // Sets first intermediate length void Linkage::setP(double P) { std::cout << "Called setP method" << std::endl; this -> intermediate_length_P; }// End of function  // Returns length of the second intermediate link double Linkage::getQ() { std::cout << "Called getQ method" << std::endl; return this -> second_length_Q; }// End of function  // Sets second intermediate length void Linkage::setQ(double Q) { std::cout << "Called setQ method" << std::endl; this -> second_length_Q = Q; }// End of function  // Returns length of the shortest link double Linkage::getShortest() { std::cout << "Called getShortest method" << std::endl; return this -> shortest_length_S; }// End of function  // Sets shortest length void Linkage::setShortest(double S) { std::cout << "Called setShortest method" << std::endl; this -> shortest_length_S = S; }// End of function  // Returns the type of motion (i.e, crank rocker, triple rocker, change point) std::string Linkage::Motion() { std::cout << "Called Motion method " if((shortest_length_S + longest_length_L) < (intermediate_length_P + second_length_Q)) return crank; // Otherwise checks If S + L > P + Q  else if((shortest_length_S + longest_length_L) > (intermediate_length_P + second_length_Q)) return triple; // Otherwise S + L = P + Q  else  return change; }// End of function

main.cpp file:

#include #include "Linkage.cpp" using namespace std; // main method definition to test the functions 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: "<< s2 << " s3: "<" s4: "<"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; 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Language in Context?

Answered: 1 week ago