Question
please fix the errors. list.cpp file #include #include #include list.hpp #include using namespace std; void SList:: create_SList() { ifstream fin; fin.open(meow.txt); if(!fin) { cout <
please fix the errors.
list.cpp file
#include
#include
#include "list.hpp"
#include
using namespace std;
void SList:: create_SList() { ifstream fin; fin.open("meow.txt"); if(!fin) { cout<<"File not found"; } else{ string line; while(!fin.eof()){ getline(fin,line); Cell* new_cell = new Cell; new_cell->data = line; new_cell->next = NULL; insert(new_cell); } print(); } fin.close();
}
void SList:: insert(Cell* node){ if(head==NULL){ head = node; } else{ Cell* temp; temp = head; if(node->data < temp->data){ head = node; node->next = temp; } while( temp->next!=NULL && node->data > temp->next->data){ temp=temp->next; } if(temp->next==NULL) temp->next = node; else{ node->next = temp->next; temp->next = node; } } }
void SList:: print(){ Cell* temp = head; Cell* ptr; while(temp){ cout<
//////
list.hpp file
#ifndef __LIST_H_INCLUDED__ #define __LIST_H_INCLUDED__
#include
struct Cell{ string data; Cell* next; };
class SList{ private: Cell* head; void insert(Cell* node); void print(); public: SList(){ head = NULL; } void create_SList(); };
#endif
///
main:
#include
using namespace std;
int main() { //banner(); SList sllist; sllist.create_SList(); //bye(); }
meow.txt(input)
meowrrrr! for me? Meowed the cat, yeow! Here is my chance, I run fast enough if a little cat in a tree. Can I get up there? Do I wish spot would make his brown dog watched a viburnum bush. I dare? Is it One summer day, neow! give me a break! I came up under the zoom, I fly! It's now it flew, here to chase a bird, but quit watching me. Maybe I can kill it. I wanna get down; please x-it. let me out of here! ~ or die! spot looks the other way. I'll slink down the back side of even worth a try oww! Oh, just when I got near enough to this tree and run
comments:
1. Using the tools is not optional. Figure out how to do it or ask for help. The file is named "tools.hpp" //#include "tool.hpp" //banner(); //bye();
2.list.hpp In this course, all data members of a class must be private. So this is inappropriate and not acceptable. Make it a class had have the class give friendship to the SList. struct Cell{ string data; Cell* next; };
3.You need to put a constructor and an destructor in every class and struct. This is not optional.
4.Please implement the kind of list that I am teaching, not something you found online. Line 16 should be declarations with initializers for scan and follow. Lint 15 should have an initializer. I expect you to add an integer count variable.
5.You have a constructor that initializes head. The initialization should be on line 15. The constructor should be =default;
6.list.cpp
Do not double-space your code. Do indent it properly. Do put a blank line and a visual divider above each function definition. These things are not optional. The penalties will increase weekly. 7.Your class .cpp file should contain exactly one #include statement, for the corresponding header file. All the rest should be in the .hpp file, as should the namespace statement. 9. Put it on one line and initialize in the declaration. The open statement is unnecessary. ifstream fin; fin.open("meow.txt"); 10. (-1) Fix this. Look at the comments from P2. Use is_open() if(!fin) { cout<<"File not found"; } 11.Put this in the Cell constructor as an optional parameter. new_cell->next = NULL; 12.while( temp->next!=NULL && node->data > temp->next->data){
temp=temp->next; } 13. A print function must NEVER modify the data structure it is printing. Split this function up into two functions: a print that just prints and a destructor that does not print.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started