#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
void imprimirRec(int alt, int larg)
{
for(int a=0; a<alt+2; a++)
{
for(int l=0; l<larg; l++)
{
if((a==0 && l==0) ||(a==alt+1 && l==0))
cout << "+--";
else if((a==0 && l==larg-1)||(a==alt+1 && l==larg-1))
cout << "--+\n";
else if(a==0 || a==alt+1)
cout << "--";
else if(l==0)
cout << "| ";
else if(l==larg-1)
cout << " |\n";
else cout << " ";
}
}
}
void writeFile(char *out_path, int alt, int larg)
{
ofstream outClientFile(out_path, ios::app);
outClientFile << "altura:" << larg << " largura:" << alt << endl;
outClientFile.close();
}
int area(int alt, int larg)
{
return alt*larg;
}
void readFile(char *in_path, char *out_path)
{
string s,s_aux,r;
int i, alt, larg, idx, idx2, a, n=1;
ifstream inClientFile(in_path, ios::in);
while(getline(inClientFile, s, '\n'))
{
s_aux = s;
i = 0;
while(i!=2)
{
switch (i)
{
case 0: idx = s_aux.find(':'); idx2 = s_aux.find(' ');
r = s_aux.substr(idx+1,idx2-idx);
alt = atoi(r.c_str());
s_aux = s_aux.substr(idx2+1,s.length());
i++;
break;
case 1: idx = s_aux.find(':');
r = s_aux.substr(idx+1,s_aux.length()-idx);
larg = atoi(r.c_str());
i++;
}
}
a = area(alt, larg);
writeFile(out_path, alt, larg);
if (alt < 10 && larg < 10)
{
imprimirRec(alt, larg);
n++;
}
else
cout << "Rectangulo " << n++ << ":altura " << alt << " largura " << larg << " area " << a << endl;
}
inClientFile.close();
}
int main(int argc, char *argv[])
{
char *in_path = argv[1];
char *out_path = argv[2];
readFile(in_path,out_path);
return 0;
}
Put your code in [code] CODE HERE [/code] tags. And state what your problem is. It's annoying reading through plain text not knowing what to look for.
Also, what is the desired outcome of the program?