Hi, I am currently having problems in my upperCase function. For 20 words out of 50 in my input file, I want to capitalize the first letter. Can someone please help me with this and lead me to the right direction. I have been trying for hours to figure it out.
Also, do I need my own function to duplicate 4 different words in the list?
Goals:
1. Read in 50 words from an input file (completed)
2. Put them in a Linked List in alphabetical order (completed)
3. 20 words should have first letter capitalized
4. Must have 4 different words to have duplicates
Input File:
jane
adam
jack
.
.
.
.
kelly
#include <fstream>
#include <string>
using namespace std;
struct nodeType {
string info;
nodeType *link;
};
void createList(nodeType*& first, nodeType*& last);
void alphasort (nodeType*& first, nodeType*& last);
void upperCase (nodeType*& first, nodeType*& last);
void printList(nodeType*& first);
int main(int argc, char *argv[])
{
nodeType *first, *last;
string words;
ifstream inData;
ofstream outData;
createList(first,last);
alphasort (first,last);
upperCase (first,last);
printList(first);
system ("PAUSE");
return 0;
}
void createList(nodeType*& first, nodeType*& last)
{
ifstream inData("input.txt"); // opens input file
string words;
nodeType *newNode;
first = new nodeType;
first->info = string("head");
first->link = NULL;
last = first;
while(inData >> words) // reads data in input file
{
newNode = new nodeType; // create new node
newNode->info = words;
newNode->link = NULL;
last->link = newNode;
last = newNode;
}
}
void nodeSwap(struct nodeType *p, struct nodeType *q) // swaps node
{
struct nodeType *t1, *t2, *t3;
if (p != q)
{
t1 = p->link; t2 = q->link; t3 = q->link->link;
p->link = q->link;
q->link = t1;
t2->link = t1->link;
t1->link = t3;
}
}
void alphasort (nodeType*& first, nodeType*& last) // sorts alphabetically by using Selection Sort
{
struct nodeType *i,*j,*min;
for (i = first; i->link != NULL; i = i->link)
{
min = i;
for (j = i->link; j->link != NULL; j = j->link)
{
if (j->link->info < min->link->info) min = j;
}
nodeSwap(i,min);
}
}
void upperCase (nodeType*& first, nodeType*& last)
{
struct nodeType *i,*j,*current;
for (i = first; i->link != NULL; i = i->link)
{
for (j = i->link; j->link != NULL; j = j->link)
{
if (j->link->info < 20)
current->info = toupper(current->info);
}
printList(first);
}
}
void printList(nodeType*& first)
{
ofstream outData("output.txt"); // Opens the outputfile
nodeType *current = first->link;
while (current != NULL)
{
outData <<current->info <<endl; // sends results to output file
current = current->link;
}
}