Question

In: Computer Science

This is C++. I would like to know the TODO list comments. #include <cstdlib> #include <iostream>...

This is C++. I would like to know the TODO list comments.

#include <cstdlib>
#include <iostream>

// TODO: 2. (1 point) Declare your Acker function prototype below:
// When done, commit with the commit message that follows, being
// sure to delete all these TODO instructions before actuallly
// executing the git commit command.
//
// CSC232-HW02 - Added Aker function prototype.
//
// Don't forget to fully document the function prototype using
// all the appropriate doxygen elements.

/**
* @brief Entry point to this application.
* @remark You are encouraged to modify this file as you see fit to gain
* practice in using objects.
*
* @param argc the number of command line arguments
* @param argv an array of the command line arguments
* @return EXIT_SUCCESS upon successful completion
*/
int main(int argc, char **argv) {
    // TODO: 4. (0.5 points) Replace *** text *** with actual call to Acker
    // function. When done, commit with the commit message that follows,
    // being sure to delete all these TODO instructions before actuallly
    // executing the git commit command.
    //
    // CSC232-HW02 - Display calculated Acker value.
    //
    std::cout << "Acker(1, 2) = " << "*** replace me with call to Acker***"
             << std::endl;
    return EXIT_SUCCESS;
}

// TODO: 3. (2 points) Define the Acker recursive function below. When done,
// commit with the commit message that follows, being sure to delete
// all these TODO instructions before actually executing the git
// commit command.
//
// CSC232-HW02 - Implemented Acker function.

// TODO: 5. (1 point) Do a box trace of Acker(1, 2) using pen and paper.
// Hand this in at the beginning of class on Friday, 17 February 2017.
// Your solution MUST be legible; no points are assigned to illegible
// papers.

This is testRunner.

#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>

#include <cppunit/Test.h>
#include <cppunit/TestFailure.h>
#include <cppunit/portability/Stream.h>

/**
* @brief Main test driver for CPPUNIT test suite.
* @remark DO NOT MODIFY THE SPECIFICATION OR IMPLEMENTATION OF THIS CLASS! ANY
* MODIFICATION TO THIS CLASS WILL RESULT IN A GRADE OF 0 FOR THIS LAB!
*/
class ProgressListener : public CPPUNIT_NS::TestListener {
public:

    ProgressListener()
    : m_lastTestFailed(false) {
    }

    ~ProgressListener() {
    }

    void startTest(CPPUNIT_NS::Test *test) {
        CPPUNIT_NS::stdCOut()<< test->getName();
        CPPUNIT_NS::stdCOut()<< "\n";
        CPPUNIT_NS::stdCOut().flush();

        m_lastTestFailed = false;
    }

    void addFailure(const CPPUNIT_NS::TestFailure& failure) {
        CPPUNIT_NS::stdCOut()<< " : " << (failure.isError() ? "error" : "assertion");
        m_lastTestFailed = true;
    }

    void endTest(CPPUNIT_NS::Test *test) {
        if (!m_lastTestFailed)
            CPPUNIT_NS::stdCOut() << " : OK";
        CPPUNIT_NS::stdCOut()<< "\n";
    }

private:
    /// Prevents the use of the copy constructor.
    ProgressListener(const ProgressListener& copy);

    /// Prevents the use of the copy operator.
    void operator=(const ProgressListener& copy);

private:
    bool m_lastTestFailed;
};

int main() {
    // Create the event manager and test controller
    CPPUNIT_NS::TestResult controller;

    // Add a listener that colllects test result
    CPPUNIT_NS::TestResultCollector result;
    controller.addListener(&result);

    // Add a listener that print dots as test run.
    ProgressListener progress;
    controller.addListener(&progress);

    // Add the top suite to the test runner
    CPPUNIT_NS::TestRunner runner;
    runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
    runner.run(controller);

    // Print test in a compiler compatible format.
    CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut());
    outputter.write();

    return result.wasSuccessful() ? 0 : 1;
}

Solutions

Expert Solution

#include <iostream>

#include <vector>

#include <fstream>

using namespace std;

vector<string> pullFile(string fileName);

void pushFile(vector<string> totalList, string fileName);

bool ifExists(string fileName);

void printList(vector<string> totalList, string fileName);

int main(){

    string trash;

    cout << "\033[2J\033[1;1H";

    string fileName;

    vector<string> totalList;

    vector<string> names;

    if (ifExists("lists.txt")){

        names = pullFile("lists.txt");

    }

    cout<<"File List: \n";

    if(names.size() <= 1){

        cout<<"No lists found.\n";

    }

    else{

        for(int c = 0; c < names.size(); c++){

            cout<<(c+1)<<". "<<names[c]<<"\n";

        }

    }

    bool flag = true;

    while (flag){

        cout<<"\nEnter the number of the list you would like to load or Enter file name for a new list.\n >", cin>>fileName, cout<<"\n";

        if(isdigit(fileName[0])){

            int x = fileName[0] - '0';

            if(x > 0 && x < names.size()){

                fileName = names[x-1];

                flag = false;

            }

            else{

                cout<<"Not a list number.\n";

            }

        }

        else{

            fileName = fileName + ".txt";

            names.push_back(fileName);

            flag = false;

        }

    }

    pushFile(names, "lists.txt");

    if (ifExists(fileName)){

        totalList = pullFile(fileName);

    }

    bool cont = true;

    while (cont){

        printList(totalList, fileName);

        int choice = 0;

        cout<<"What would you like to do?\n";

        cout<<"1. Add item.\n";

        cout<<"2. Remove item.\n";

        cout<<"3. Quit.\n";

        cout<<">", cin>>choice, cout<<"\n";

        while(cin.fail()){

            cin.ignore();

            cin.clear();

            rewind(stdin);

            cout<<">", cin>>choice, cout<<"\n";

        }

        if(choice == 1){

            string newItem;

            cout<<"Enter new item: ", cin>>newItem, cout<<"\n";

            if(cin.fail()){

                cin.ignore();

                cin.clear();

                rewind(stdin);

                cout<<"Enter new item: ", cin>>newItem, cout<<"\n";

            }

            totalList.push_back(newItem);

        }

        else if(choice == 2){

            int itemNumber = 0;

            cout<<"Enter item number to delete: ", cin>>itemNumber, cout<<"\n";

            while(cin.fail() || itemNumber < 1 || itemNumber > totalList.size()){

                cin.ignore();

                cin.clear();

                rewind(stdin);

                cout<<"Enter item number to delete: ", cin>>itemNumber, cout<<"\n";

            }

            totalList.erase(totalList.begin() + (itemNumber-1));

        }

        else if(choice == 3){

            cont = false;

            pushFile(totalList, fileName);

            cout<<"Exiting.\n";

        }

        else{

            cout<<"Invalid Input!\n";

            cin.clear();

            cin.ignore();

        }

    }

}

vector<string> pullFile(string fileName){

    vector<string> totalList;

    fstream ioFile;

    ioFile.open(fileName.c_str(), fstream::in);

    string bullet;

    while (!ioFile.eof()){

        getline(ioFile, bullet);

        if(!bullet.empty()){

            totalList.push_back(bullet);

        }

    }

    ioFile.close();

    return totalList;

}

void pushFile(vector<string> totalList, string fileName){

    fstream ioFile;

    ioFile.open(fileName.c_str(), fstream::out);

    for(int c = 0; c < totalList.size(); c++){

        if(!totalList[c].empty()){

           ioFile<<totalList[c]<<"\n";

        }

    }

    ioFile.close();

}

bool ifExists(string fileName){

    ifstream infile(fileName.c_str());

    return infile.good();

}

void printList(vector<string> totalList, string fileName){

    cout << "\033[2J\033[1;1H";

    cout<<"List: "<<fileName<<"...\n";

    for(int c = 0; c < totalList.size(); c++){

            cout<<(c+1)<<". "<<totalList[c]<<"\n";

        }

    cout<<"\n\n\n\n\n";

}


Related Solutions

/* * C++ Program to Implement Hash Tables with Quadratic Probing */ #include <iostream> #include <cstdlib>...
/* * C++ Program to Implement Hash Tables with Quadratic Probing */ #include <iostream> #include <cstdlib> #define MIN_TABLE_SIZE 10 using namespace std; //----------------------------------------------------------------------- // Node Type Declaration //----------------------------------------------------------------------- enum EntryType { Legi, Emp, Del }; //----------------------------------------------------------------------- // Node Declaration //----------------------------------------------------------------------- struct HashTableEntry { int e; enum EntryType info; }; //----------------------------------------------------------------------- // Table Declaration //----------------------------------------------------------------------- struct HashTable { int size; HashTableEntry *t; }; //----------------------------------------------------------------------- // Function: isPrime Function // Return whether n is prime or not //----------------------------------------------------------------------- bool isPrime (int n)...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits>...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits> #include <vector> using namespace std; // // CLASS: NODE // class Node{ public: int value = 0; // our node holds an integer Node *next = nullptr; // our node has a pointer to the next Node Node(int i){ // contructor for our Node class value = i; // store a copy of argument "i" in "value" next = nullptr; // be sure next...
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact {...
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact { public: Contact(string init_name = "", string init_phone = "000-000-0000"); void setName(string name); void setPhone(string phone); string getName()const; string getPhone()const; friend ostream& operator << (ostream& os, const Contact& c); friend bool operator == (const Contact& c1, const Contact& c2); friend bool operator != (const Contact& c1, const Contact& c2); private: string name, phone; }; Contact::Contact(string init_name, string init_phone) { name = init_name; phone = init_phone;...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib>...
fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib> #include <ctime> void insertion_sort(int array[], int size, int start); void heap_sort(int B[], int n); void build_max_heap(int B[], int n); void max_heapify(int B[], int i, int n); void quick_sort(int B[], int p, int r); int partition(int B[], int p, int r); int main() {    int m = 10, Nf = 20000, Ns = 1000, delta = 1000, A[m][Nf];    for (int i = 0;...
Recursion and Iteration in C++ Locate the TODO comments in the hw02.h file. These comments provide...
Recursion and Iteration in C++ Locate the TODO comments in the hw02.h file. These comments provide direction on what needs to be done. // hw02.h #ifndef CSC232_HW02_H #define CSC232_HW02_H // TODO: All pre-conditions must be validated using the assert function imported from the following library. // TODO: You are not allowed to use the pow function in this assignment! #include <cassert> #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE !FALSE #endif #define USE_MAIN_INPUT_FILE FALSE #define USE_DEMO_INPUT_FILE FALSE #define...
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char**...
complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char** argv) { int number, sum, count; // Write a while loop that reads a number from the user and loop // until the number is divisible by 7 cout << "What is the number? "; cin >> number; while ( ... ) { ... } cout << number << " is divisible by 7!! << endl << endl; // Write a for loop that...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
Hi I would like to see an example in c++ of Stack As Linked List I...
Hi I would like to see an example in c++ of Stack As Linked List I need a seek() function which receives a double number X and which returns in which position in the stack is X. If the value X is not in the stack, the function should return -1
Please use C++, linked list and Bubble Sort to slove this problem. #include <iostream> #include <time.h>...
Please use C++, linked list and Bubble Sort to slove this problem. #include <iostream> #include <time.h> using namespace std; struct ListNode { int data; ListNode *next; ListNode(int x) : data(x), next(nullptr) {} }; class LinkedList { private: ListNode *head = nullptr; public: void addNode(int x) { ListNode *p = new ListNode(x); if (head == nullptr) head = p; else { ListNode *q = head; while (q->next != nullptr) q = q->next; q->next = p; } } void display() { ListNode...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT