Liked-List to Convert Char to UPPERCASE
Apr 18, 2016 at 2:31am UTC
Hello,
I am trying to convert a character sentence to an to UPPERCASE using Linked-List queue.
Below is my code, but it's not compiling, and I can't figure out the problem.
Please help me.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
//Headerfile
#ifndef LINKEDQUEUETYPE_H
#define LINKEDQUEUETYPE_H
#include<iostream>
using namespace std;
struct nodeType
{
char info;
nodeType * link;
};
class linkedQueueType
{
public :
void initializeQueue();
bool isEmptyQueue();
linkedQueueType front();
linkedQueueType back();
void addQueue(const linkedQueueType& newItem);
linkedQueueType();
~linkedQueueType();
private :
nodeType * queueFront;
nodeType * queueRear;
};
#endif // LINKEDQUEUETYPE_H
//.cpp file
#include "linkedQueueType.h"
#include<iostream>
using namespace std;
//Add Queue
void linkedQueueType::addQueue(const char & newItem)
{
nodeType * newNode;
newNode = new nodeType;
newNode->info = newItem;
newNode->link = NULL;
if (queueFront == NULL)
{
queueFront = newNode;
queueRear = newNode;
}
else
{
queueRear->link = newNode;
queueRear = newNode;
}
}
//IsEmpty
bool linkedQueueType::isEmpty()
{
return (queueFront == NULL);
}
//IsFull
bool linkedQueueType::isFull()
{
return false ;
}
//Initialize Queue
void linkedQueueType::initializeQueue()
{
nodeType * temp;
while (queueFront != NULL)
{
temp = queueFront;
queueFront = queueFront->link;
delete temp;
}
QueueRear = NULL;
}
//Front
linkedQueueType linkedQueueType::front() const
{
assert(queueFront != NULL);
return queueFront->info;
}
//Back
linkedQueueType linkedQueueType::back() const
{
assert(queueRear != NULL);
return queueReal->info;
}
//Default Constructor
linkedQueueType::linkedQueueType()
{
queueFront = NULL;
queueRear = NULL;
}
//Destructor
linkedQueueType::~linkedQueueType()
{
initializeQueue();
}
//main.cpp
#include "linkedQueueType.h"
#include <ctype.h>
#include<iostream>
using namespace std;
int main()
{
char ch;
linkedQueueType queue;
cout << "Please enter a sentence: \n" ;
cin.get(ch);
while (ch != '\n' )
{
toupper(ch);
queue.addQueue(ch);
}
cout << "Queue Elements: " ;
while (!queue.isEmptyQueue())
{
cout << queue.front() << " " ;
queue.deleteQueue();
}
cout << endl;
return 0;
}
Apr 18, 2016 at 7:20am UTC
Return Value
The uppercase equivalent to c, if such value exists, or c (unchanged) otherwise. The value is returned as an int value that can be implicitly casted to char.
http://www.cplusplus.com/reference/cctype/toupper/
1 2 3
char ch;
cout << "Please enter a sentence: \n" ;
cin.get(ch);
You're trying to fit a string in a character which isn't going to work. Use
std::string
and loop through each character.
Topic archived. No new replies allowed.