CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: C++

  1. #1
    Join Date
    Jun 2012
    Posts
    6

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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?)
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jun 2012
    Posts
    6

    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

  4. #4
    Join Date
    Jun 2012
    Posts
    6

    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.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    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.

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: C++

    I would suggest you start by reading an introductory book to C++. It will help you greatly for the future.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  7. #7
    Join Date
    Feb 2012
    Posts
    23

    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.

  8. #8
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    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).
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured