All pastes #142411 Raw Edit

Unnamed

public text v1 · immutable
#142411 ·published 2006-08-21 13:07 UTC
rendered paste body
/* simple program to test choral ring implementation */

#include <iostream>
#include <cstdlib>
using namespace std;
void printMenu(); 

#include "ring.h"

int main()
{
    char choice = '1';    // user's choice
    int n,k, moves, remnode;
    ring r;
    ring f;
    while (choice != '8')
    {
        printMenu(); 
        cout << "\tChoice? ";
        cin >> choice ;
        switch (choice)
        {
            case ('1') : cout << "Please enter n and k " << endl;
                         if(!(cin >> n >> k) || n < 5 || k < 2 || k > n/2)
                             cout << "Invalid input " << endl;
                         else
                             {
			     	r.create(n,k);
			 	ring f(r);
				
				}
                         break;
            case ('2') : if(!f.empty()) f.dumpShort();break;
            case ('3') : if(!f.empty()) f.dumpLong(); break;
            case ('4') : if(!f.empty()) f.display();  break;
            case ('5') : cout << "Please enter number of places to move ";
                         cin >> moves;
                         if(moves < 0)
                            cout << "Invalid input " << endl;
                         else if(!f.empty())
                           f.move(moves);
                         break;
            case('6') : if(!f.empty())
				cout << f.getCurrent() << endl;
                        break;
            case('7') : cout << "Please enter label of node to be removed ";
                        cin >> remnode;
                        if(remnode > 0 && r.hasMember(remnode) && f.hasMember(remnode))
                        {   
				f.remove(remnode);
			}
                        else
                           cout << remnode <<" does not exist " << endl;
            case('8') : break;
            default   : cout << "Invalid input " << endl;
         }
    }
    return EXIT_SUCCESS;
}  

void printMenu()
{
    /* displays a menu of options */
    cout << "\n\n\t\tChordal Rings " << endl << endl;
    cout << "\t1 Create a Ring " << endl;
    cout << "\t2 Dump Short " << endl;
    cout << "\t3 Dump Long " << endl;
    cout << "\t4 Display Ring  " << endl;
    cout << "\t5 Move " << endl;
    cout << "\t6 Display Current " << endl;
    cout << "\t7 Remove " << endl;
    cout << "\t8 Quit " << endl << endl;
   
}