|
-
June 28th, 2012, 11:11 AM
#1
C++
Can you help me to develop a program which integers are placed in brackets fractions in quotation marks, and insert it in text file, that's it.
-
June 28th, 2012, 11:21 AM
#2
Re: C++
What have you done so far? (Besides, I note that your problem description is very vague, e.g., how do you obtain input?)
-
June 28th, 2012, 11:28 AM
#3
Re: C++
I just need the simplest way to do excercise.
i think there could be used this algoritm:
if(a==round(a)){
Insert in ()
}
else {
insert in ""
}
But im zero at C++, i just need this stupid excercise to be done
-
June 28th, 2012, 11:33 AM
#4
Re: C++
a small description, people writes and number in programm, then if its string, then it inserts it in text file in breckets, if you enter somthing like 3,14 then it inserts in " " and thats it.
-
June 28th, 2012, 12:06 PM
#5
Re: C++
You're doing a terrible job at explaining your problem. Regardless, nobody will do it for you. Try it yourself and ask for assistance when you're stuck. As it is, I doubt anybody has any idea what you're trying to do.
-
July 2nd, 2012, 01:35 AM
#6
Re: C++
I would suggest you start by reading an introductory book to C++. It will help you greatly for the future.
-
July 3rd, 2012, 01:51 PM
#7
Re: C++
People obviously don't want to do your homework for you, but you could do something along the lines of:
Code:
int main()
{
char stringIn[40];
fstream fin, fout;
fin.open("pathIn.txt", ios::in);
fout.open("pathOut.txt", ios::in);
while(!fin.eof())
{
fin >> stringIn[40];
if(isDouble(stringIn))
fout << "[" << stringIn << "]" << endl;
else
if(isInt(stringIn))
fout << "\"" << stringIn << "\"" << endl;
else
if(isString(stringIn))
fout << stringIn << endl;
}
}
This isn't exactly what you asked for, but I didn't feel like spending too much time trying to decipher your question.
Now, there are more than likely header files out there that have isDouble functions, but you can make your own.
For example:
Code:
bool isString(char stringIn[40])
{
if(!isInt(stringIn) && !isDouble(stringIn))
return true;
else
return false;
}
bool isInt(char stringIn[40])
{
for(int i = 0; i <= 39; i++)
{
if(stringIn[i] > '9' || stringIn[i] < '0')
return false;
}
return true;
}
bool isDouble(char stringIn[40])
{
for(int i = 0; i <= 39; i++)
{
if((stringIn[i] > '9' || stringIn[i] < '0') && stringIn[i] != '.')
return false;
}
if(isInt(stringIn)) //implying that a double must have a '.'
return false;
return true;
}
Don't forget to include function prototypes.
Note: I wrote this code in codeguru's "compiler," there are bound to be errors.
-
July 6th, 2012, 09:11 AM
#8
Re: C++
The decimal separator is not everywhere in the world the same. In the states it's a . (dot) but for example in belgium it's a , (comma).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|