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

I c++ experts, i need some help this project ive been stuck on for a bit. Any he

ID: 3571551 • Letter: I

Question

I c++ experts, i need some help this project ive been stuck on for a bit. Any help would be appreciated.

For this project, create a dynamic container class so your program can be used for any sized Apache weblog. Each line of the file will be a single string that will be stored in a dynamic array (do not use vector for this assignment!). The dynamic array should be declared in the private section of your container class. Feel free to use your Project 1 code for this assignment, but be sure to modify it to use an array, not a vector. Make a backup copy of your project 1 code first, just in case.

The container class should include the following functions to work with the weblog.cpp file (see below).  

void add(); a function to open the weblog.txt file and add a line from the file as a string to the private array. If the array is filled to capacity, a private function should be called to grow the array before the add is performed.

int size(); a function to return the total number of lines in the container.

void lineNum( int index); a function to display a line from the container when a line number is provided.  Note: This is the line number, which is the array's index number + 1.

For testing purposes, you can use the following larger versions of the original weblog.txt from project 1. Right click the files below to save the files to your computer.

weblog_small.txt

weblog_medium.txt

Requirements

Class private data member that is a dynamic array to hold strings and all required functions. (5 points)

Class private function to grow the array when it is filled to capacity. (5 points)

Create another function that adds to the array. If the array is filled to capacity, the private function should be called to grow the array before the add is performed. (5 points)

Make sure you class implementation is in a separate .cpp file and not part of your header file. Remember to #include the header file in your implementation. (3 points)

Follow Style Guidelines. (2 points)

Explanation / Answer


#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
using namespace std;
class Weblog{
private:
int capacity;
  
string *lineStore;
public:
Weblog();
~Weblog();
void resize(int newSize);
void add();
int size();
void lineNum( int index);
};
Weblog::Weblog(){
capacity=100;
lineStore=new string[capacity];
}
Weblog::~Weblog()
{
delete[] lineStore;
}
void Weblog:: add(){
std::string line;
ifstream file("weblog.txt");
if ( !file.is_open() )
{
std::cout<<"File could not be opened"<<std::endl;
}
else {

if( file.good() )
{
int i=0;
while (file.good())
{
if(i>capacity-2){
resize(capacity+200);
}
getline(file,lineStore[i]);

i++;

}
}
}
}
void Weblog::resize(int newSize) {
string *temp;
temp = new string[newSize];
for (int i = 0; i < capacity; i++) {
temp[i]=lineStore[i];
}
delete[] lineStore;
lineStore = temp;
capacity = newSize;
}

int Weblog:: size()
{
return capacity;
}
void Weblog::lineNum(int index){
std::cout<<lineStore[index+1]<<std::endl;
}
int main(){
int index;
Weblog weblog;
weblog.add();
std::cout<<"Size of file "<<weblog.size()<<std::endl;
std::cout<<"please enter the index "<<std::endl;
std::cin>>index;
std::cout<<"Line at index "<<index<<std::endl;
weblog.lineNum(index);
  
return 0;
}

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