concludes the Circles class for eac obje that 18 destroyed times is this printed
ID: 3778881 • Letter: C
Question
concludes the Circles class for eac obje that 18 destroyed times is this printed? Why? Lab 13.3 Arrays as Data Members of classes Retrieve program floatarray.cpp and temperatures .txt from the Lab 13 folder. The code is as follows: This program reads floating point data from a data file and places those values into the private data member called values a floating point array 11 of the FloatList class. Those values are then printed to the screen. The input is done by a member function called GetList. The output is done by a member function called Print List. The amount of data read in is stored in the private data member called length. The member function Get List is called first so that length can be initialized to Eero. include kios tream> include continuesExplanation / Answer
Here is the code for you:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int MAX_LENGTH = 50;
class FloatList
{
public:
void getList(ifstream&);
void printList() const;
FloatList();
~FloatList();
private:
int length;
float values[MAX_LENGTH];;
};
int main()
{
ifstream tempData;
FloatList list;
cout<<fixed<<showpoint;
cout<<setprecision(2);
tempData.open("temperatures.txt");
list.getList(tempData);
list.printList();
return 0;
}
FloatList::FloatList()
{
length = 0;
}
void FloatList::getList(ifstream &fin)
{
while(!fin.eof())
{
fin>>values[length];
length++;
}
}
void FloatList::printList() const
{
for(int i = 0; i < length; i++)
cout<<values[i]<<endl;
}
FloatList::~FloatList()
{
}
Exercise 1: printList() is not allowed to do any modification to the member variables. To indicate this, the const keyword is used, where as, getList() is allowed to do the modification. So, it is not having the keyword const.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.