Like Tree2Likes
  • 2 Post By grumpy

Converting C++ program into C

This is a discussion on Converting C++ program into C within the C++ Programming forums, part of the General Programming Boards category; Can anyone help me convert this C++ program into a C program? Code: #include <iostream> using namespace std; class date ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    1

    Exclamation Converting C++ program into C

    Can anyone help me convert this C++ program into a C program?

    Code:
    #include <iostream>
    using namespace std;
    
    
    
    
        class date
        {
              int month;
              int day;
              int year;
         public:  
              date (int month = 1, int day = 1, int year = 2001)
              {
                   date::month = month;
                   date::day = day;
                   date::year = year;
              };
             
             
             
    
    
    
    
              void showDate();
              ~date(){}
    
    
         };
         
    void date::showDate(){
         cout << month << "/" << day << "/" << year << endl;
         }
    
    
    int main()
    
    
    
    
    {
       int month;
       int day;
       int year;
     
       
       string monthName[12] = {"January","February","March","April","May","June","July",
       "August","September","October","November","December"};
            
    
    
         
         
         cout << "enter month (between 1 and 12)" << endl;
         cin >> month;
     
         
         if (month > 12 || month < 1)
         {
               month = 1;
         }
       
       
         cout << "enter day (between 1 and 31)" << endl;
         cin >> day;
         
         if (day > 31 || day < 1)
         {
               day = 1;
         }
         
         
         cout << "enter year (between 1900 and 2010)"<< endl;
         cin >> year;
         
         if (year > 2010 || year < 1900)
         {
              year = 2001;
         }
          
    
    
       
        date newDate(month, day, year);
        newDate.showDate();
         cout << monthName[month-1]<< " " << day << ", " << year << endl;
         cout << day << " " <<  monthName[month-1] << " " << year << endl;
    
    
        system ("PAUSE");
        return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,265
    Why do you want to do this? Do you know C? Do you know C++?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,005
    Do you know that you can interchange C and C++? By using a C interface, you can call your C++ code from C (you would still have to compile C++ code with a C++ compiler, of course).
    Do you also know that you can compile C with a C++ compiler (you will have to adapt your code a little bit, though, since C++ isn't 100% backwards compatible).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,625
    Quote Originally Posted by laserlight View Post
    Why do you want to do this? Do you know C? Do you know C++?
    I suspect the OP has homework to do in a C class, has found a C++ sample, and is hoping someone will complete their homework by converting the code.
    Salem and rags_to_riches like this.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help converting a java program to C
    By rpmischris in forum C Programming
    Replies: 8
    Last Post: 08-09-2012, 09:34 PM
  2. Converting Time Program
    By greeziakattack in forum C Programming
    Replies: 4
    Last Post: 01-18-2012, 01:23 AM
  3. Converting a program from C++ to C
    By pedrocosta03 in forum C Programming
    Replies: 3
    Last Post: 06-28-2011, 11:33 PM
  4. Help converting array program to link list program
    By hsmith1976 in forum C++ Programming
    Replies: 0
    Last Post: 02-14-2010, 09:50 PM
  5. Why is this program converting to integers
    By 3DPhreak in forum C++ Programming
    Replies: 3
    Last Post: 05-31-2004, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21