Site hosted by Angelfire.com: Build your free website today!
« December 2008 »
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Open Community
Post to this Blog
You are not logged in. Log in
C++ Programs from Random Places
Sunday, 16 July 2006
Print Calendar
//THIS PROGRAM PRINTS A CALENDAR
//**NOTE**: THIS MATERIAL IS NOT COPYRIGHTED AND IS FREE
//FOR PERSONAL USE AND DISTRIBUTION
#include
#include
#include
int getNumberOfDays(int month,int year)
{
switch(month)
{
case 1 : return(31);
case 2 : if(year%4==0)
return(29);
else
return(28);
case 3 : return(31);
case 4 : return(30);
case 5 : return(31);
case 6 : return(30);
case 7 : return(31);
case 8 : return(31);
case 9 : return(30);
case 10: return(31);
case 11: return(30);
case 12: return(31);
default: return(-1);
}
}
char *getName(int odd)
{
switch(odd)
{
case 0 :return("Sunday");
case 1 :return("Monday");
case 2 :return("Tuesday");
case 3 :return("Wednesday");
case 4 :return("Thursday");
case 5 :return("Friday");
case 6 :return("Saturday");
default:return("Error in getName() module.Invalid argument
passed");
}
}
int getOddNumber(int day,int mon,int year)
{
int res=0,t1,t2,y=year;
year = year-1600;
while(year>=100)
{
res=res+5;
year=year-100;
}
res=(res%7);
t1=((year-1)/4);
t2=(year-1)-t1;
t1=(t1*2)+t2;
t1=(t1%7);
res = res+t1;
res=res%7;
t2=0;
for(t1=1;t1 {
t2+=getNumberOfDays(t1,y);
}
t2 = t2+day;
t2 = t2%7;
res = res+t2;
res = res%7;
if(y>2000)
res=res+1;
res = res%7;
return res;
}
char *getWeek(int dd,int mm,int yy)
{
int odd;
if(!(mm>=1 && mm<=12))
{
return("Invalid month value");
}
if(!(dd>=1 && dd<=getNumberOfDays(mm,yy)))
{
return("Invalid date");
}
if(yy>=1600)
{
odd = getOddNumber(dd,mm,yy);
odd=odd%7;
return(getName(odd));
}
else
{
return("
Please give year more than 1600");
}
}
void printMonth(int mon,int year,int x,int y)
{
int nod,odd,cnt,d=1,x1=x,y1=y;
if(!(mon>=1 && mon<=12))
{
printf("
INVALID MONTH");
getch();
return;
}
if(!(year>=1600))
{
printf("
INVALID YEAR");
getch();
return;
}
if(x<=0)
x=wherex();
if(y<=0)
y=wherey();
gotoxy(x,y);
textcolor(RED);
cprintf("S");
textcolor(YELLOW);
cprintf(" M T W T F S");
/* 1234567891234567891234567 */
textcolor(7);
cprintf("");
y++;
nod=getNumberOfDays(mon,year);
odd=getOddNumber(d,mon,year);
switch(odd)
{
case 0 : x=x;
cnt=1;
break;
case 1 : x=x+4;
cnt=2;
break;
case 2 : x=x+8;
cnt=3;
break;
case 3 : x=x+12;
cnt=4;
break;
case 4 : x=x+16;
cnt=5;
break;
case 5 : x=x+20;
cnt=6;
break;
case 6 : x=x+24;
cnt=7;
break;
default : printf("

INVALID DATA FROM THE getOddNumber()
MODULE");
return;
}
gotoxy(25,25);
gotoxy(x,y);
printf("%02d",d);
for(d=2;d<=nod;d++)
{
if(cnt%7==0)
{
y++;
cnt=0;
x=x1-4;
}
x = x+4;
cnt++;
gotoxy(x,y);
printf("%02d",d);
}
}
main()
{
char ch='k';
int dd,mm,yy;
while(ch!='0')
{
clrscr();
printf("




1.Know the day");
printf("
2.Print the month");
printf("
0.EXIT");
printf("

ENTER YOUR CHOICE : ");
flushall();
fflush(stdin);
ch=getche();
clrscr();
switch(ch)
{
case '1': printf("Enter date (DD MM YYYY) : ");
scanf("%d %d %d",&dd,&mm,&yy);
printf("
Day is : %s",getWeek(dd,mm,yy));
flushall();
getch();
break;
case '2' : printf("Enter month and year (MM YYYY) : ");
scanf("%d %d",&mm,&yy);
printf("

");
printMonth(mm,yy,-1,-1);
flushall();
getch();
break;
case '0' : exit(0);
}
}
}

Posted by poetry/maddoxtheconqueror at 12:01 AM CDT
Post Comment | Permalink | Share This Post
Sunday, 11 June 2006
Java Maze
//THIS IS A “RANDOM MAZE” PROGRAM WRITTEN IN JAVA
//OBVIOUSLY IT’S NOT C++, BUT THOSE WELL-VERSED IN PROGRAMMING SHOULD
//BE ABLE TO FIGURE IT OUT
//**NOTE**: THIS IS NOT COPYRIGHTED AND IS FREE FOR PERSONAL
//USE AND DISTRIBUTION

import java.io.*;
import java.util.*;


public class Lab29ast
{
public static void main(String args[]) throws IOException
{
System.out.println("\nLab 29a 80/100 Point Version\n");
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter random starting seed ===>> ");
int seed = Integer.parseInt(input.readLine());

Maze maze = new Maze(seed);
maze.displayMaze();
maze.solveMaze();
maze.displayMaze();
maze.mazeSolution();
}
}


class Maze
{

private char mat[][]; // 2d character array that stores the maze display
private Coord currentMove; // object that stores current maze position
private MyStack visitStack; // stack that stores location that have been visited


class Coord
// Coord is a class that stores a single maze location.
{
private int rPos;
private int cPos;
public Coord (int r, int c) { rPos = r; cPos = c; }
public boolean isFree() { return (rPos == 0 && cPos == 0); }
public void setPos(int r, int c) { rPos+= r; cPos+= c; }
}


public Maze(int seed)
// constructor which generates the random maze, random starting location
// and initializes Maze class values. If the random value equals 0 the maze
// store an 'X' otherwise it store an 'O' in the maze.
{
Random random = new Random(seed);
int startRow, startCol;
mat = new char[12][12];
for (int r = 0; r < 12; r++)
for (int c = 0; c < 12; c++)
{
if (r == 0 || c == 0 || r == 11 || c == 11)
mat[r][c] = 'X';
else
{
int rndInt = random.nextInt(2);
if (rndInt == 0)
mat[r][c] = 'X';
else
mat[r][c] = 'O';
}
}
mat[0][0] = 'O';
startRow = random.nextInt(12);
startCol = 11;
mat[startRow][startCol] = '.';
visitStack = new MyStack();
currentMove = new Coord(startRow,startCol);
visitStack.push(currentMove);
}


void displayMaze() throws IOException
// displays the current maze configuration
{
System.out.println("\nRANDOM MAZE DISPLAY\n");
for (int r = 0; r < 12; r++)
{
for (int c = 0; c < 12; c++)
System.out.print(mat[r][c] + " ");
System.out.println();
}
System.out.println();
pause();
}


public void solveMaze() throws IOException
// This methods solves the maze with private helper method .
// A loop is needed to repeat getting new moves until either a maze solution
// is found or it is determined that there is no way out off the maze.
{
System.out.println("\n>>>>> WORKING .... SOLVING MAZE <<<<<\n");
for(int a = 0;a<10000;a++)
getMove();
}


public void mazeSolution()
// Short method to display the result of the maze solution
{
if (currentMove.isFree())
System.out.println("\nTHE MAZE HAS A SOLUTION.\n");
else
System.out.println("\nTHE MAZE HAS NO SOLUTION.\n");
}


private boolean inBounds(int r, int c)
// This method determines if a coordinate position is inbounds or not
{
if(r>11||c>11)
return false;
else
return true;
}


private boolean getMove() throws IOException
// This method checks eight possible positions in a counter-clock wise manner
// starting with the (-1,0) position. If a position is found the method returns
// true and the currentMove coordinates are altered to the new position
{
boolean found = false;
int x = currentMove.cPos;
int y = currentMove.rPos;
int nx = x;
int ny = y;

if(mat[ny=y][nx=x-1]=='O')
{
found = true;
}
else if(mat[ny=y+1][nx=x-1]=='O')
{
found = true;
}
else if(mat[ny=y+1][nx=x]=='O')
{
found = true;
}
else if(mat[ny=y+1][nx=x+1]=='O')
{
found = true;
}
else if(mat[ny=y][nx=x+1]=='O')
{
found = true;
}
else if(mat[ny=y-1][nx=x+1]=='O')
{
found = true;
}
else if(mat[ny=y-1][nx=x]=='O')
{
found = true;
}
else if(mat[ny=y-1][nx=x-1]=='O')
{
found = true;
}
else if(mat[ny=y][nx=x-1]=='.')
{
found = true;
}
else if(mat[ny=y+1][nx=x-1]=='.')
{
found = true;
}
else if(mat[ny=y+1][nx=x]=='.')
{
found = true;
}
else if(mat[ny=y+1][nx=x+1]=='.')
{
found = true;
}
else if(mat[ny=y][nx=x+1]=='.')
{
found = true;
}
else if(mat[ny=y-1][nx=x+1]=='.')
{
found = true;
}
else if(mat[ny=y-1][nx=x]=='.')
{
found = true;
}
else if(mat[ny=y-1][nx=x-1]=='.')
{
found = true;
}

if(found)
{
currentMove.setPos(ny-y,nx-x);
mat[ny][nx] = '.';
}
return found;
}

private void pause() throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String dummy;
System.out.print("\nPress to continue ===>> ");
dummy = input.readLine();
}


}



Posted by poetry/maddoxtheconqueror at 12:01 AM CDT
Post Comment | Permalink | Share This Post
Tuesday, 16 May 2006
Intro to Recursion
//THIS PROGRAM IS SHORT AND SWEET. IT USES RECURSION TO REVERSE
//THE ORDER IN WHICH ITEMS ARE ENTERED
//**NOTE**: THIS IS NOT COPYRIGHTED MATERIAL AND IS FREE FOR PERSONAL
//USE AND DISTRIBUTION
#include

using namespace std;

void rev( )
{ char ch;
cin.get(ch);
if (ch != '\n')
{ rev();
cout.put(ch);
}
}

int main( )
{ rev();
}


Posted by poetry/maddoxtheconqueror at 12:01 AM CDT
Post Comment | Permalink | Share This Post
Sunday, 9 April 2006
Basic Structs
//THIS IS JUST AN INTRODUCTION TO STRUCTS
//**NOTE**: THIS CODE IS NOT COPYRIGHTED AND IS FREE FOR USE
//AND DISTRIBUTION

struct node {
int x;
node *next;
};

int main()
{
node *root; // This won't change, or we would lose the list in memory
node *conductor; // This will point to each node as it traverses the list

root = new node; // Sets it to actually point to something
root->next = 0; // Otherwise it would not work well
root->x = 12;
conductor = root; // The conductor points to the first node
if ( conductor != 0 ) {
while ( conductor->next != 0)
conductor = conductor->next;
}
conductor->next = new node; // Creates a node at the end of the list
conductor = conductor->next; // Points to that node
conductor->next = 0; // Prevents it from going any further
conductor->x = 42;

conductor = root;
while ( conductor != NULL ) {
cout<< conductor->x;
conductor = conductor->next;
}

}

Posted by poetry/maddoxtheconqueror at 12:01 AM CDT
Post Comment | Permalink | Share This Post
Friday, 17 March 2006
Find the Day of the Year
//THIS CALCULATES THE DAY OF THE YEAR(OUT OF 365/366)
//**NOTE**: THIS MATERIAL IS NOT COPYRIGHTED AND IS FREE FOR
//PERSONAL USE AND DISTRIBUTION
#include
using namespace std;

bool febdays(int year)
//PURPOSE: determines if year is a leap year
//PRECONDITION: uses certain divisors to find leap years
//POSTCONDITION: returns true or false for variable year
{
if(year%4==0 && year%100!=0){ //any year evenly divisible by 4 but not by 100 and 400
return true;
}
else if(year%4==0 && year%100==0 && year%400==0){
return true;
}
else if(year%4==0 && year%100==0 && year%400!=0){
return false;
}
else{
return false; //for years not evenly divisible by 4
}
}
int daynum(int month, int day,int year)
//PURPOSE: finds day of year
//PRECONDITION: takes in month, day, and year entered
//POSTCONDITION: returns day of year
{
int julian_day=0; //a julian day refers to the day on the Julian calendar
if(month==1){
julian_day=0+day;
}
else if(month==2){
julian_day=31+day;
}
else if(month==3){
if(febdays(year)==true){
julian_day=60+day;
}
else{
julian_day=59+day;
}
}
else if(month==4){
if(febdays(year)==true){
julian_day=91+day;
}
else{
julian_day=90+day;
}
}
else if(month==5){
if(febdays(year)==true){
julian_day=121+day;
}
else{
julian_day=120+day;
}
}
else if(month==6){
if(febdays(year)==true){
julian_day=152+day;
}
else{
julian_day=151+day;
}
}
else if(month==7){
if(febdays(year)==true){
julian_day=182+day;
}
else{
julian_day=181+day;
}
}
else if(month==8){
if(febdays(year)==true){
julian_day=213+day;
}
else{
julian_day=212+day;
}
}
else if(month==9){
if(febdays(year)==true){
julian_day=244+day;
}
else{
julian_day=243+day;
}
}
else if(month==10){
if(febdays(year)==true){
julian_day=274+day;
}
else{
julian_day=273+day;
}
}
else if(month==11){
if(febdays(year)==true){
julian_day=305+day;
}
else{
julian_day=304+day;
}
}
else if(month==12){
if(febdays(year)==true){
julian_day=335+day;
}
else{
julian_day=334+day;
}
}
return julian_day;
}
int main()
//PURPOSE: finds julian day on calendar(0-365/366)
//PRECONDITION: asks user for month, day, and year
//POSTCONDITION: returns julian day
{
int month, day, year;
cout<<"Enter the month: "< cin>>month;
if(month<1 || month>12){
return 0;
}
cout<<"Enter the day: "< cin>>day;
if(day<1){ //even if "day" is > the number of days in the month, the correct Julian day will be returned
return 0;
}
cout<<"Enter the year: "< cin>>year;
cout< return 0;
}

Posted by poetry/maddoxtheconqueror at 12:01 AM CST
Post Comment | Permalink | Share This Post
Friday, 10 February 2006
Calculating Pi
//ThIS IS A NEAT PROGRAM THAT CALCULATES PI DEPENDING ON HOW MUCH
//ACCURACY YOU WANT
//**NOTE**: THIS MATERIAL IS NOT COPYRIGHTED AND IS OPEN FOR PUBLIC
//USE AND DISTRIBUTION

#include
#include "Dice.h"
using namespace std;

int main ()
//PURPOSE: use Monte Carlo Method to estimate pi
//PRECONDITIONS: none
//POSTCONDITIONS: displays the estimated value of pi
{
float totaldarts; // total number of darts to throw
float inside=0; // number of darts inside unit circle
float x,y; // coordinates of point where dart lands
float countdarts; // count darts thrown
float pi; // estimate for pi
Dice die(101); //create die with 101 sides

// prompt user for number of darts to throw
cout << "Enter number of darts to throw: ";
cin >> totaldarts;

// loop to throw and count darts
for(countdarts=0; countdarts<=totaldarts; countdarts++){
x=die.Roll();
y=die.Roll();
x=(x-1)/100;
y=(y-1)/100;
if(x*x + y*y <=1){
inside++;
}
}
// compute estimate of pi
pi=4.00*(inside/totaldarts);

// display estimate
cout << "The estimate of pi is: " << pi << endl;

return 0;
}

class Dice
{
public:
// constructor to create a die
Dice(int sides);
// return random roll of die
int Roll();
// how many sides this die has
int NumSides() const;
// number of times this die rolled
int NumRolls() const;

private:
// count # of times this die rolled
int myRollCount;
// save # of sides on this die
int mySides;
};


Posted by poetry/maddoxtheconqueror at 12:01 AM CST
Post Comment | Permalink | Share This Post
Monday, 23 January 2006
Fun Bank Account Program
//THIS IS GOOD FOR USING STRUCTS AND ARRAYS
//**NOTE**: THIS IS NOT COPYRIGHTED MATERIAL AND IS FREE FOR
//DISTRIBUTION AND PERSONAL USE
#include
#include
#include
#include
using namespace std;

// Create bank account data type
struct acct { // bank account data
int num; // account number
string name; // owner of account
float balance;// balance in account
};

// Function Prototypes
int find(acct bank[ ], int numaccts, int goal);
void insert(acct bank[ ], int &numaccts, acct newacct);
void remove(acct bank[], int &numaccts, acct deleteacct);
void transfer(acct bank[], int &numaccts, float amount, acct account);

int main ()
//PURPOSE: simulate a small bank
//PRECONDITIONS: existing accounts in file account.txt
// in project folder
//POSTCONDITIONS: finds, inserts and deletes accounts
{
acct bank[1000]; // list of bank accounts
int numaccts; // total number of accounts
ifstream vault; // file with list of bank accounts
string command; // user request
int goal; // account number to find or delete
int loc; // subscript of account in bank list
acct account; // a bank account
float amount;
// read existing accounts from file
vault.open("accounts.txt");
numaccts=0;
vault >> bank[0].num >> bank[0].name >> bank[0].balance;
while (!vault.eof()) {
numaccts = numaccts + 1;
vault >> bank[numaccts].num >> bank[numaccts].name
>> bank[numaccts].balance;
}

// display dollar values with two digits to right of decimal point
cout << setiosflags(ios::fixed) << setprecision(2);

// get ready to process user commands
cout << "The bank is now open." ;
cout << endl << endl;

// loop to process user commands
cout << endl << "----------" << endl;
cout << "Enter a command (exit to stop): ";
cin >> command;
while (command != "exit") {

if (command == "find") { // FIND COMMAND
// get account to find
cout << "Enter account number: ";
cin >> goal;
// search for account
loc = find(bank, numaccts, goal);
// display account data or error message
if (loc >= 0) {
cout << "Account: " << bank[loc].num << "\t"
<< "Owner: " << bank[loc].name << "\t"
<< "Balance: " << bank[loc].balance << endl;
}
else {
cout << "Account " << goal <<" does not exist." << endl;
}
}

else if (command == "list") { // LIST COMMAND
cout << "List of accounts:" << endl;
for (loc=0; loc cout << "Account: " << bank[loc].num << "\t"
<< "Owner: " << bank[loc].name << "\t"
<< "Balance: " << bank[loc].balance << endl;
}
}

else if (command == "insert") { // INSERT COMMAND
cout << "Enter new account data: " << endl;
cout << "Account number: ";
cin >> account.num;
cout << "Account name: ";
cin >> account.name;
cout << "Account balance: ";
cin >> account.balance;
insert(bank, numaccts, account);
}
else if(command=="remove"){ //REMOVE COMMAND
cout<<"Enter the account number to remove: "< cin>>account.num;
while(find(bank,numaccts,account.num) == -1){
cout<<"Invalid. Enter a valid account number: "< cin>>account.num;
}
remove(bank,numaccts,account);
}

else if(command=="transfer"){
cout<<"Enter first account number: "< cin>>account.num;
while(find(bank,numaccts,account.num) == -1){
cout<<"Invalid. Enter a valid account number: "< cin>>account.num;
}
cout<<"Enter the balance to transfer: "< cin>>amount;
transfer(bank,numaccts,amount,account);
cout<<"Enter second account number: "< cin>>account.num;
while(find(bank,numaccts,account.num) == -1){
cout<<"Invalid. Enter a valid account number: "< cin>>account.num;
}
amount=-1*amount;
transfer(bank,numaccts,amount,account);
}

else { // INVALID COMMAND
cout << "Invalid command." << endl;
}

cout << endl << "----------" << endl;
cout << "Enter a command (exit to stop): ";
cin >> command;
}

// exit command from user
cout << endl << "----------" << endl;
cout << "The bank is now closed.";
cout << endl << endl;

return 0;
}

int find(acct bank[ ], int numaccts, int goal)
//PURPOSE: search for a goal account in the list of accounts
//PRECONDITIONS: 0 <= numaccts, numaccts is number of account in
// list of accounts (i.e., bank)
//POSTCONDITIONS: returns the subscript of goal account or -1 if
// the goal account is not found
{
int k; // loop variable

//search the the goal account in list of accounts
for (k=0; k if (bank[k].num == goal) {
return k;
}
}

// didn't find goal account
return -1;
}

void insert(acct bank[ ], int &numaccts, acct newacct)
//PURPOSE: insert a new account into the account list
//PRECONDITIONS: 0 <= numaccts, numaccts is number of account
// in account list, newacct is a new account,
// account list is in order by account number
//POSTCONDITIONS: account list modified to add new account,
// order of account list is maintained
{
int k,j; // loop variables

// find place to put new account to maintain order of list
k=0;
while ((bank[k].num < newacct.num) && (k < numaccts)) {
k = k + 1;
}

// add new account to list
if (k == numaccts) { // goes at end of list
bank[numaccts] = newacct;
numaccts = numaccts + 1;
}
else { // goes in middle of list
// make room to add new account
for (j=numaccts; j>k; j--) {
bank[j] = bank[j-1];
}
// add new account to vacated spot in list
bank[k] = newacct;
numaccts = numaccts + 1;
}
}
void remove(acct bank[], int &numaccts, acct deleteacct)
//PURPOSE: remove an account from the account list
//PRECONDITION: 0<=numaccts, numaccts is # of accounts in list
// account list is in order by account number
//POSTCONDITION: returns list with one less account, which is the one
// that the user chose to remove
{
int x,y; //loop variables
y=find(bank, numaccts, deleteacct.num);
for(x=y; y<=numaccts; y++){
bank[y]=bank[y+1];
}
numaccts=numaccts-1;
}
void transfer(acct bank[], int &numaccts, float amount, acct account)
{
int i;
i=find(bank,numaccts,account.num);
bank[i].balance=bank[i].balance - amount;
}

Posted by poetry/maddoxtheconqueror at 12:01 AM CST
Post Comment | Permalink | Share This Post
Tuesday, 20 December 2005
Sorting Words Alphabetically Using Nodes
//NOTE: FEEL FREE TO USE AND/OR DISTRIBUTE THIS CODE AS YOU LIKE
//THIS IS NOT COPYRIGHTED MATERIAL

#include
#include
using namespace std;

struct Node
{
string name;
Node * next;
};

struct List
{
Node * front;
Node * back;
};

void displayList(List L)
//PURPOSE: display contents of list
//PRECONDITIONS: L must be a valid list
//POSTCONDITIONS: list L display on screen
{
Node * n;

// traverse list and display contents
cout << "Beginning of List" << endl;
n = L.front;
while (n != NULL) {
cout << "\t" << n->name << endl;
n = n->next;
}
cout << "End of List" << endl << endl;
}

Node * searchList(List L, string str)
//PURPOSE: search list L for place to insert str
//PRECONDITIONS: L must be a valid list
//POSTCONDITIONS: returns pointer to previous node of first
// node with value >= str

{
Node * n;
Node * prev;

// traverse list to find node that contains str
n = L.front;
prev = NULL;
while (n != NULL) {
if (n->name >= str) {
return prev;
}
prev = n;
n = n->next;
}

// goes at end of list
return prev;
}

void insert(List &L, Node * n)
//PURPOSE: insert new node in a list
// keepping list ordered
//PRECONDITIONS: L must be a valid list
//POSTCONDITIONS: List L has new node inserted
{
Node * after; // insert new node after this node

// find where to insert node
after = searchList(L, n->name);

// handle NULL list
if (L.front == NULL) {
L.front = n;
L.back = n;
n->next = NULL;
}
// handle insert at front of list
else if (after == NULL) {
n->next = L.front;
L.front = n;
}
// handle insert in middle or end of list
else {
n->next = after->next;
after->next = n;
if (n->next == NULL) {
L.back = n;
}
}
}

void deleteNode(List &L, Node * n)
{
Node * del;
if(n==NULL){
del=L.front;
L.front=del->next;
n = L.front;
if(n->next==NULL){
L.back=n;
}
delete del;
}
else{
del=n->next;
n->next = del->next;
if(n->next==NULL){
L.back=n;
}
delete del;
}
}

int main()
//PURPOSE: create a list of words in alphabetical order
//PRECONDITIONS: none
//POSTCONDITIONS: displays list of words in alphabetical order
{
string s; // word from user
List L; // list of words
Node * n; // list node

//initialize list L
L.front = NULL;
L.back = NULL;

// prompt user for words and insert them into list
// in alphabetical order
cout << "Enter next word (! to stop): ";
cin >> s;
while (s != "!") {
n = new Node;
n->name = s;
insert(L, n);
cout << "Enter next word (! to stop): ";
cin >> s;
}

// display words in alphabetical order
displayList(L);

// prompt user for words to delete from the list
cout << "Enter word to delete (! to stop): ";
cin >> s;
while(s != "!") {
n = searchList(L, s);
deleteNode(L, n);
cout << "Enter word to delete (! to stop): ";
cin >> s;
}

// display list with words deleted
displayList(L);

return 0;
}

Posted by poetry/maddoxtheconqueror at 12:01 AM CST
Post Comment | Permalink | Share This Post

Newer | Latest | Older