Right Triangle Cpp Triangle Program
Righttrianglerighttrianglecpprighttrianglerighttrianglecppthis
Righttrianglerighttrianglecpprighttrianglerighttrianglecppthis
RightTriangle/rightTriangle.cpp RightTriangle/rightTriangle.cpp // This file includes implementations for functions of the right // triangle class. #include #include using namespace std ; #include "rightTriangle.h" // Default constructor RightTriangle :: RightTriangle () { base = 0 ; height = 0 ; } // SET functions (for storing data in private data members) void RightTriangle :: setHeight ( double h ) { height = h ; } void RightTriangle :: setBase ( double b ) { base = b ; } // Calculate length of hypotenuse using // Pythagorean Theorem double RightTriangle :: calcHypotenuse () { return sqrt ( base base + height height ); } __MACOSX/RightTriangle/._rightTriangle.cpp RightTriangle/rightTriangle.h // This file defines the specifications for a class to store // attributes of a right triangle class RightTriangle { private: // PRIVATE data members double base; double height; public: // PUBLIC member functions RightTriangle(); // Default constructor void setHeight(double h); // SET functions void setBase(double b); // Calculate length of hypotenuse double calcHypotenuse(); }; __MACOSX/RightTriangle/._rightTriangle.h RightTriangle/testTriangle.cpp RightTriangle/testTriangle.cpp // This program calculates various parameters of a // right triangle. #include using namespace std ; #include "rightTriangle.h" int main () { // Declaration double base , height ; RightTriangle aTriangle ; // Input cout > base ; cout > height ; // Move data to object aTriangle . setBase ( base ); aTriangle . setHeight ( height ); // Calculations and output cout
Widget 5.4 9. Bludger 9.1 15. Zeeter 7.7 1. Sub_Tweezer 12.3 5. Woofle 3.7 49.79 c++practice3a3b/partMgr.cpp c++practice3a3b/partMgr.cpp // This program manages a list of parts. #include #include #include using namespace std ; // Attributes for one part struct partInfo { int number ; char name [ 30 ]; double weight ; double price ; }; const int MAX_LIST_SIZE = 100 ; // Function prototypes int menu (); void buildPartsList ( partInfo partList [], int & listSize ); void searchParts ( partInfo partList [], int numParts ); void listParts ( partInfo partList [], int & numParts ); void insertPart ( partInfo list [], int & numElems ); void deletePart ( partInfo list [], int & numElems ); partInfo getPartInfo (); void writeColumnHeading (); void writeLineReport ( partInfo aPart ); void writePartsList ( partInfo partList [], int listSize ); //---------------------------------------------------------------------- // MAIN PROGRAM int main () { int action ; // User menu choice partInfo partList [ MAX_LIST_SIZE ]; // Main list of parts int numParts ; // Size of parts list buildPartsList ( partList , numParts ); // Read parts list from file do { action = menu (); // Prompt for user choice switch ( action ) // Take action on user choice { case 1 : searchParts ( partList , numParts ); break ; case 2 : insertPart ( partList , numParts ); break ; case 3 : deletePart ( partList , numParts ); break ; case 4 : listParts ( partList , numParts ); break ; }; } while ( action != 5 ); // If not "quit" repeat // Otherwise exit writePartsList ( partList , numParts ); // Write list to file cout > choice ; if ( choice 5 ) cout 5 ); return choice ; } //---------------------------------------------------------------------- // This function reads a list of parts from a file and populates // and array of part records void buildPartsList ( partInfo partList [], int & listSize ) { // Declarations partInfo aPart ; ifstream InFile ( "partList.txt" ); if ( InFile . fail () ) // Test for file existence { cout > aPart . number >> aPart . name >> aPart . weight >> aPart . price ; while ( !
InFile . eof () && i > aPart . number >> aPart . name >> aPart . weight >> aPart . price ; } listSize = i ; // Size of list is number of parts InFile . close (); } //---------------------------------------------------------------------- // This function searches the current parts list for a given part. // The part number is passed as the key. A linear search routine // is utilized. void searchParts ( partInfo partList [], int numParts ) { int partNumberKey ; cout > partNumberKey ; int index = 0 ; // Used as a subscript to search array int position = - 1 ; // To record position of search value bool found = false ; // Flag to indicate if the value was found while ( index = 0 ) { writeColumnHeading (); // Print heading writeLineReport ( partList [ position ]); } else cout > aPart . number ; // Search for and delete part int ptr = 0 ; // Scan list for deletion target while ( aPart . number != list [ ptr ]. number && ptr > aPart . number ; cout > aPart . name ; cout > aPart . weight ; cout > aPart . price ; cout