using C++ i am trying to make a text file display the following below. this is m
ID: 3832118 • Letter: U
Question
using C++ i am trying to make a text file display the following below. this is my code so far. it does not compile.
/*Size: M
Gender: M
Color: R
Sleeve type: Ss
Fading: Y
Streching: Y
Shrinking: N
Warming: Y
Reflecting: Y
Soaking: N */
#include
#include
#include
using namespace std;
struct shirt
{
char size;
char gender;
char color;
char sleeveType;
bool fading;
bool stretch;
bool shrinks;
bool warms;
bool reflect;
bool soaks;
public:
char insertSize(char S, char M, char L)
{
size = s;
}
char insertGender(char M, char F)
{
gender = g;
}
char insertColor(char R, char Bl, char G, char p, char bk, char y, char br)
{
color = c;
}
char insertSleeveType(char Ss, char Ls, char Ns)
{
sleeveType = st;
}
bool insertFading(bool y, bool n)
{
fading = f;
}
bool insertStretch(bool y, bool n)
{
stretch = sr;
}
bool insertShrinks(bool y, bool n)
{
shrinks = sh;
}
bool insertWarms(bool y, bool n)
{
warms = w;
}
bool insertReflect( bool y, bool n)
{
reflect = r;
}
bool insertSoaks(bool y, bool n)
{
soak = sk;
}
}
};
int main()
{
ifstream in("newshirt.txt");
vector shirts;
while (0)
{
shirt temp;
getline(in, temp.size);
getline(in, temp.gender);
getline(in, temp.color);
getline(in, temp.sleeveType);
getline(in, temp.fading);
getline(in, temp.stretch);
getline(in, temp.shrink);
getline(in, temp.warms);
getline(in, temp.reflect);
getline(in, temp.soaks);
shirts.push_back(temp);
}
for (shirt &x : shirts)
{
cout << "Size: " << x.size << endl;
cout << "Gender: " << x.gender << endl;
cout << "Color: " << x.color << endl;
cout << "Sleeve type: " << x.sleeveType << endl;
cout << "Fading: " << x.fading << endl;
cout << "Stretching: " << x.stretch << endl;
cout << "Shrink: " << x.shink << endl;
cout << "Warms: " << x.warms << endl;
cout << "Reflects light: " << x.reflect << endl;
cout << "Soaks: " << x.soaks << endl;
cout << endl << endl;
}
return 0;
}
Explanation / Answer
#include
#include
#include
using namespace std;
struct shirt
{
char size;
char gender;
char color;
char sleeveType;
bool fading;
bool stretch;
bool shrinks;
bool warms;
bool reflect;
bool soaks;
public:
char insertSize(char S, char M, char L)
{
size = s;
}
char insertGender(char M, char F)
{
gender = g;
}
char insertColor(char R, char Bl, char G, char p, char bk, char y, char br)
{
color = c;
}
char insertSleeveType(char Ss, char Ls, char Ns)
{
sleeveType = st;
}
bool insertFading(bool y, bool n)
{
fading = f;
}
bool insertStretch(bool y, bool n)
{
stretch = sr;
}
bool insertShrinks(bool y, bool n)
{
shrinks = sh;
}
bool insertWarms(bool y, bool n)
{
warms = w;
}
bool insertReflect( bool y, bool n)
{
reflect = r;
}
bool insertSoaks(bool y, bool n)
{
soak = sk;
}
}
};
int main()
{
ifstream in("newshirt.txt");
vector shirts;
while (0)
{
shirt temp;
getline(in, temp.size);
getline(in, temp.gender);
getline(in, temp.color);
getline(in, temp.sleeveType);
getline(in, temp.fading);
getline(in, temp.stretch);
getline(in, temp.shrink);
getline(in, temp.warms);
getline(in, temp.reflect);
getline(in, temp.soaks);
shirts.push_back(temp);
}
for (shirt &x : shirts)
{
cout << "Size: " << x.size << endl;
cout << "Gender: " << x.gender << endl;
cout << "Color: " << x.color << endl;
cout << "Sleeve type: " << x.sleeveType << endl;
cout << "Fading: " << x.fading << endl;
cout << "Stretching: " << x.stretch << endl;
cout << "Shrink: " << x.shink << endl;
cout << "Warms: " << x.warms << endl;
cout << "Reflects light: " << x.reflect << endl;
cout << "Soaks: " << x.soaks << endl;
cout << endl << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.