Posts

Showing posts from 2010

Insert and Reverse Nodes

/*  * midtermPraj.cpp  *  *  Created on: Nov 16, 2010 *  *    *      Description:  *      Write a C++ class that establishes a data structure for storing floating-point values. Implement  *   the data structure using a singly linked list. Required methods:  * Insert_Nodes, Display_Nodes, and Reverse_Nodes.  */ #include <iostream> #include <fstream> using namespace std; const char INPUT_PATH_FILE[] = "C:\\Users\\Shiva\\workspace\\midtermPraj\\floatingPoints.txt"; // Structure for our float node struct Float_Node { float Value; // Holds value struct Float_Node* Next; // Holds the address. }; class linkedList { private: Float_Node* base; Float_Node* p; Float_Node* q; //Float_Node* r; public: linkedList(); void insertNodes(double); void displayNodes(); void reverseNodes(); ~linkedList(); }; linkedList::linkedList() { // Default Constructor base = NULL; } linkedList::~linkedList() { //Destructor while(base)

Square Root using Recursive Function

/*  * SquareRoot.cpp  *  *  Created on: Dec 2, 2010  *      Program Description:  *      This program would calculate the square root of a number entered by user using  *      recursive function as well as the non recursive version of it.  */ #include<iomanip> #include<cmath> #include<iostream> using namespace std; const double tol = 1.0E-4; // Tolerance constant. // Function Prototypes double sqrRootRecursive(double, double, double); double sqrRootNonRecursive(double, double, double); // Function Definitions double sqrRootRecursive(double number, double approx, const double tol) { // Using Recursive function to calculate Square Root of user input. if (fabs (approx * approx - number) <= tol) return approx; else if (fabs((approx * approx) - number) > tol) approx = sqrRootRecursive(number, (approx * approx + number) / (2 * approx), tol); return approx; } double sqrRootNonRecursive(double number, double approx, double tol) {

Circular Queue

/*  * pshrestha_a3.cpp  *  *  Created on: Nov 16, 2010  *      Program Description:  *      A class is written that implements a "Circular Queue" data structure for storing  *      and retrieving floating point values. The methods created are: Enqueue(), Dequeue(),  *      isEmpty(), isFull(), makeEmpty(), goToHead().  *     A switch statement is used in the main program for the efficiency of its application  *     to handle the structured data.  */ #include <iostream> #include <cctype> #include <iomanip> using namespace std; const int MAX_ELEMENTS = 17; // Declaring maximum number of elements. struct Float_Node { // Structure for the node containing a value and the next node. double Value; struct Float_Node* Next; }; class CircularQueue { private: Float_Node *rear; Float_Node *p; // Current int nodeCounter; // To count the nodes. public: CircularQueue(); bool Enqueue(double); double Dequeue(bool&); bool is

Concept of recursive function to take user input of two numbers and performs an addition of those two numbers

/*  * p4_pshr_Adder.cpp  *  *     Created on: Nov 23, 2010  * Program Description:  * This program uses the concept of recursive function to take user input of two numbers and  * performs an addition of those two numbers.  */ #include <iostream> #include <cctype> #include <iomanip> using namespace std; class Add { private: public: unsigned int Adder(unsigned int, unsigned int); }; unsigned int Add::Adder(unsigned int num1,unsigned int num2) { // This recursive function very smartly deals with the 3 possible cases of the input number // entered by the user being both equal to zero, one number being equal to zero and other number // being equal to zero. if (num1 != 0 && num2 != 0) { // If both number entered by user becomes zero, this recursive function comes to and end // and moves to the next line. But, if both the numbers are non-zero, then, it adds "2" // the times either one of the number is not equal to zer

C++ class that implements a “stack” data structure for storing floating-point values. Required methods: Push, Pop, isEmpty, and isFull.

/*  * pshrestha_a2.cpp  *  *  *      Created on: Nov 7, 2010  * Write a C++ class that implements a “stack” data structure for storing floating-point values. Required methods: Push, Pop, isEmpty, and isFull. Feel free to come up with any additional methods you think a programmer would find useful. Implement your “stack” object using a singly linked list. Write an associated “driver” C++ program that demonstrates the use of your “stack” class.  */ #include <iostream> #include <cctype> #include <iomanip> using namespace std; const int MAX_ELEMENTS = 10; // Maximum Number of nodes our stack supports. struct Stack_Node { // Structure for the node containing a value and the next node. double Value; struct Stack_Node* Next; }; class Stack { private: struct Stack_Node* p; // Current struct Stack_Node* top; int nodeCounter; // To count the nodes. public: Stack(); bool push(double&); bool isEmpty(); bool isFull(); double po

C++ program that reads a textual data file and builds linked lists using the data therein.

/*  * pshrestha_1.cpp  *  *  Created on: Oct 27, 2010  *   Write a C++ program that reads a textual data file and builds linked lists using the data therein. Each line of the file contains a letter (either I or F) following by a corresponding numeric value. In each line, an integral value is preceded by character I and a floating-point value is preceded by character F. An "I integer" line may or may not be followed by one or more "F float" lines. Your program is to process each line of the file and build linked lists. An "integer" linked list (nodes sorted ascendingly by integer value) will be created using the "I integer" lines. "F float" lines will begin/continue another singly linked list "off of" the integer node corresponding to the integer value and node processed immediately before (again, any "I integer" line may or may not be followed by one or more "F float" lines). Any list of floating-poi