Programming for the methods of the Use the following class declaration as refere
ID: 3892980 • Letter: P
Question
Programming for the methods of the Use the following class declaration as reference class ListClass public: I It does not matter how it was implemented ListClass) -Listclass) bool Insert(Computer, unsigned int); Computer Get(unsigned int)const; int Indexof(const Computer&)const; bool Remove(unsigned int); int krite(ostream&)const; int Read (istrea&); bool IsEmpty)const; unsigned int Size)const; the string and the 24. Assume you h ave a list of Computers. Class Computer has a method ToString that returns representation of the Computer. Write a function that takes as parameters the list of Computers anit name of a file. Your function will write the string letters. The order that the students a representation of each computer to the file in capital ppear in the file will be reversed (from the last to the first). Your method wil return the records only the methods of the ADT List listed above. Call the function SendToFile e number of records written to file, or -1 if there was a write error at any point. UseExplanation / Answer
int SendToFile(ListClass l, string filename){
if (l.isEmpty()){
return 0;
}
ofstream fout(filename.c_str());
if (!fout){
return -1;
}
int count = 0;
for (int i = l.Size(); i>=0; i--){
Computer *c = l.Get(i);
if (c == NULL)
return -1;
string s = c->ToString();
for (int j = 0; s.length(); i++)
s[i] = toupper(s[i]);
fout << s << endl;
count++;
}
fout.close();
return count;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.