Classes Constructor and Destructor
Feb 27, 2014 at 1:58am UTC
Hello, I am writing few lines of codes for my project and I am not sure how to approach this problem.
The instruction says:
Add a function call loadDocument that takes the name of the file. The function will read in the text file and create a new Line for each sentence read with Line id equal to the location in the text file. After, set the linecount.
Is Line a class or an array of the class? In previous classes, I did make an array of classes. Also, how do you mean by location in the text file. Can you please help me?
Here's what I have so:
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
/* Start of Class Line */
class Line
{
public :
int id;
Line();
Line(string str1 )
{
int id = rand();
*str=str1;
}
~Line();
int getWordCount();
void setString(string str1);
void setWordCount(int value1);
int getCharCount();
void setCharCount(int value2);
private :
string* str;
int wordcount;
int charcount;
};
Line::Line()
{
int id = rand();
string* str = new string;
}
Line::~Line()
{
delete str;
}
void Line::setString(string str1)
{
*str = str1;
}
int Line::getWordCount()
{
return wordcount;
}
void Line::setWordCount(int value1)
{
wordcount = value1;
}
int Line::getCharCount()
{
return charcount;
}
void Line::setCharCount(int value2)
{
charcount = value2;
}
/* End of Class Line */
/* Start of Class Document */
class Document
{
public :
int id;
int getLineCount();
void setLineCount(int value3);
int getwordcount();
void setwordcount(int value4);
~Document();
Document()
{
Line* line = new Line[];
}
private :
int linecount;
int wordcount;
string name;
Line* line;
};
Document::~Document()
{
delete [] line;
}
int Document::getLineCount()
{
return linecount;
}
void Document::setLineCount(int value3)
{
linecount = value3;
}
int Document::getwordcount()
{
return wordcount;
}
void Document::setwordcount(int value4)
{
wordcount = value4;
}
/* End of Class Document */
int main()
{
int number;
cout << "Please enter number " << endl;
cin >> number;
switch (number)
{
case 1:
cout << "Load Document " << endl;
case 2:
cout << "Output Document " << endl;
case 3:
cout << "Parse Document " << endl;
case 4:
cout << "Analyze Document " << endl;
default :
cout << "Exit " << endl;
}
return 0;
}
void loadDoucment()
{
ifstream myfile ("example.text" );
if (myfile.is_open() )
{
}
}
Topic archived. No new replies allowed.