Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++! Having a really hard time comipling this. Here is the main that i have so f

ID: 3725826 • Letter: C

Question

C++! Having a really hard time comipling this. Here is the main that i have so far. Was able to get number 2 done but i need help getting the third. The image shows my main and my attempt. The code at the bottom is the Slinkedlist.h which i have tried to get to work. Any help is great. If you can get this to complie even better! this is for C++! thank you! Again not number 2 but number 3! number 2 is done! THANK YOU!

#ifndef Slinkedlist_h
#define Slinkedlist_h

#include <stdio.h>
#pragma once
#include <stdexcept>
using namespace std;
template <typename E> class SLinkedList; // forward declaration to be used when declaring SNode
template <typename E>
class SNode { // singly linked list node
private:
E elem; // linked list element value
SNode<E> *next; // next item in the list
friend class SLinkedList<E>; // provide SLinkedList access
};
template <typename E>
class SLinkedList { // a singly linked list
public:
SLinkedList(); // empty list constructor
~SLinkedList(); // destructor
bool empty() const; // is list empty?
E& front(); // return front element
void addFront(const E& e); // add to front of list
void addBack(const E& e);
void removeFront(); // remove front item list
int size() const; // list size
void countVowel(const E& e);
int numVowels() const;
int numConsonants() const;
//void reverse(const E& ptr);
private:
SNode<E>* head; // head of the list
int n; // number of items
int vowelCount;
int consonantCount;
};
template <typename E>
SLinkedList<E>::SLinkedList() // constructor
: head(NULL), n(0), vowelCount(0), consonantCount(0) { }

template <typename E>
bool SLinkedList<E>::empty() const // is list empty?
{
return head == NULL; // can also use return (n == 0);
}
template <typename E>
E& SLinkedList<E>::front() // return front element
{
if (empty()) throw length_error("empty list");
return head->elem;
}
template <typename E>
SLinkedList<E>::~SLinkedList() // destructor
{
while (!empty()) removeFront();
}
template <typename E>
void SLinkedList<E>::addFront(const E& e) { // add to front of list
SNode<E>* v = new SNode<E>; // create new node
v->elem = e; // store data
v->next = head; // head now follows v
head = v; // v is now the head
n++;
}
template <typename E>
void SLinkedList<E>::addBack(const E& e) {
// create node
SNode<E>* v = new SNode<E>;
v->elem = e;
v->next = NULL;
countVowel(e);
if(!head) { // empty list becomes the new node
head = v;
return;
} else { // find last and link the new node
SNode<E>* last = head;
while(last->next) last=last->next;
last->next = v;
}
}
template <typename E>
void SLinkedList<E>::reverse(const E& ptr) {
if (empty()) throw length_error("empty list");
SNode<E>* old = head; // save current head
while(old->next){
old->next = reverse(this);
}
head = old->next;
delete old;
}
template <typename E>
void SLinkedList<E>::removeFront() { // remove front item
if (empty()) throw length_error("empty list");
SNode<E>* old = head; // save current head
head = old->next; // skip over old head
delete old; // delete the old head
n--;
}
template <typename E>
int SLinkedList<E>::size() const { // list size
return n;
}
template <typename E>
int SLinkedList<E>::numVowels() const {
return vowelCount;
}
template <typename E>
int SLinkedList<E>::numConsonants() const {
return consonantCount;
}
template <typename E>
void SLinkedList<E>::countVowel(const E& e){ // list size
if (isalpha(e)){
if(e == 'a' || e == 'A' || e == 'e' || e == 'E' || e == 'i' || e == 'I' || e == 'o' || e == 'O' || e == 'u' || e == 'U'){
vowelCount++;
}
// if (e == ' ') {
// return;
// }
else{
consonantCount++;
}
}
}
#endif /* Slinkedlist_hpp */

#2 [6 points Use the template class SlinkedList discussed in class to implement a singly linked list of characters that store all the characters read from a line of text. The line of text will contain upper and lower case letters, digits, punctuation signs and white spaces. Add two member functions countVowel and countConsonant that count the number of vowels in the list, respectively the number of consonants in the list. For example, if the line of text given as a input is "Is dark at 6?!", the link list looks like: 6 The number of vowels is 3 and the number of consonants is 5. #3 [4 points] Given a singly linked list as in Problem 2, write a public member function void SLinkedList:reverseO to re-orient the next pointers of all the nodes in a list to each point to the previous element. Add a helper function as needed. Use the code available from SLinkedList.h on our Github https://github.com/apanangadan/CSUF-CPSC_131 with modification to illustrate your approach For the example given in Problem 2, the linked list will look like: 6

Explanation / Answer

I didn't added main. I just replaced reverse method in your code. If you need entire code, give me a comment.

#ifndef Slinkedlist_h

#define Slinkedlist_h

#include <stdio.h>

#pragma once

#include <stdexcept>

using namespace std;

template <typename E>

class SLinkedList; // forward declaration to be used when declaring SNode

template <typename E>

class SNode

{ // singly linked list node

private:

E elem; // linked list element value

SNode<E> *next; // next item in the list

friend class SLinkedList<E>; // provide SLinkedList access

};

template <typename E>

class SLinkedList

{ // a singly linked list

public:

SLinkedList(); // empty list constructor

~SLinkedList(); // destructor

bool empty() const; // is list empty?

E &front(); // return front element

void addFront(const E &e); // add to front of list

void addBack(const E &e);

void removeFront(); // remove front item list

int size() const; // list size

void countVowel(const E &e);

int numVowels() const;

int numConsonants() const;

void reverse(const E& ptr);

private:

SNode<E> *head; // head of the list

int n; // number of items

int vowelCount;

int consonantCount;

};

template <typename E>

SLinkedList<E>::SLinkedList() // constructor

: head(NULL), n(0), vowelCount(0), consonantCount(0)

{

}

template <typename E>

bool SLinkedList<E>::empty() const // is list empty?

{

return head == NULL; // can also use return (n == 0);

}

template <typename E>

E &SLinkedList<E>::front() // return front element

{

if (empty())

throw length_error("empty list");

return head->elem;

}

template <typename E>

SLinkedList<E>::~SLinkedList() // destructor

{

while (!empty())

removeFront();

}

template <typename E>

void SLinkedList<E>::addFront(const E &e)

{ // add to front of list

SNode<E> *v = new SNode<E>; // create new node

v->elem = e; // store data

v->next = head; // head now follows v

head = v; // v is now the head

n++;

}

template <typename E>

void SLinkedList<E>::addBack(const E &e)

{

// create node

SNode<E> *v = new SNode<E>;

v->elem = e;

v->next = NULL;

countVowel(e);

if (!head)

{ // empty list becomes the new node

head = v;

return;

}

else

{ // find last and link the new node

SNode<E> *last = head;

while (last->next)

last = last->next;

last->next = v;

}

}

template <typename E>

void SLinkedList<E>::reverse(const E &ptr)

{

if (empty())

throw length_error("empty list");

SNode<E> *prev = NULL, *current = head, *next;

while (current != NULL)

{

next = current->next;

current->next = prev;

prev = current;

current = next;

}

head = prev;

}

template <typename E>

void SLinkedList<E>::removeFront()

{ // remove front item

if (empty())

throw length_error("empty list");

SNode<E> *old = head; // save current head

head = old->next; // skip over old head

delete old; // delete the old head

n--;

}

template <typename E>

int SLinkedList<E>::size() const

{ // list size

return n;

}

template <typename E>

int SLinkedList<E>::numVowels() const

{

return vowelCount;

}

template <typename E>

int SLinkedList<E>::numConsonants() const

{

return consonantCount;

}

template <typename E>

void SLinkedList<E>::countVowel(const E &e)

{ // list size

if (isalpha(e))

{

if (e == 'a' || e == 'A' || e == 'e' || e == 'E' || e == 'i' || e == 'I' || e == 'o' || e == 'O' || e == 'u' || e == 'U')

{

vowelCount++;

}

// if (e == ' ') {

// return;

// }

else

{

consonantCount++;

}

}

}

#endif /* Slinkedlist_hpp */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote