Anyone into C++ progamming?

mk3supra

New Member
Apr 22, 2005
231
0
0
Decatur, IL
www.supramania.com
I am taking a C++ programming class for engineer students and was wondering if any one here has experience with it. I have a home work assignment im looking for help on. Any help is appreciated.
 
Last edited:

SupraMario

I think it was the google
Mar 30, 2005
3,467
6
38
38
The Farm
LOL, your not supposed to pay someone to program for you. Your supposed to learn and understand the work. I used to do a little bit of C++ but I'm heavily involved with JAVA now, its hard, but it is multi platform which is great.
 

BigKO

Member
Nov 5, 2008
326
0
16
Riverside
LOL taking c++ now, depending on how far along you are (I'm a beginner) I may be able to help out a little bit, but don't think I am willing to do it for you I ahve enough homework with 4 midterms this week on my own
 

BigKO

Member
Nov 5, 2008
326
0
16
Riverside
mk3supra;1306611 said:
Well, I am a beginner also and don't understand what is going on in class because I cannot understand the teacher when she talks. I just need help writing a program and understanding it.

Oh ok, yeah i am going through that right now too, midterms tomorrow, if you have any specific questions, such as syntax or a general way to go about programming something I will be glad to help.
 

adampecush

Regular Supramaniac
May 11, 2006
2,118
3
38
Edmonton
D34DC311;1306105 said:
LOL, your not supposed to pay someone to program for you. Your supposed to learn and understand the work. I used to do a little bit of C++ but I'm heavily involved with JAVA now, its hard, but it is multi platform which is great.

bah, I was forced to take a similar class, and have not used C++ since.

Off the record, I may have done a few assignments in "groups". Had I not, I probably would not have passed the class all those years ago...
 

mk3supra

New Member
Apr 22, 2005
231
0
0
Decatur, IL
www.supramania.com
Yea, same here, its required for my degree. If it were my choice I wouldn't be in the class because I have no interest in programming. This is what I have to do

Write a program that includes two functions next_day( ) and prior_day( ).

Function next_day( ) increments a date by one day. Test your function to ensure that it correctly increments days into a new month and into new year.

prior_day( ) function decrements a date by one day. Test your function to ensure that it correctly decrements days into a prior month and into prior year.

your output should be as shown below:

>welcome to date processor.
>Please enter the date
>11 22 2008
> next day - 11/23/2008
>prior day – 11/22/2008
>please enter 'y' if you want to continue or 'Q' to quit: y
>please enter the date
>11 30 2008
>next day – 1/31/2008
>prior day – 11/29/2008
>please enter 'y' if you want to continue or 'Q' to quit: y
>please enter the date
> 2 28 2008
>next day - 2/29/2008
>prior day – 2/28/2008
>please enter 'y' if you want to continue or 'Q' to quit: y
>please enter the date
>31 1 2009
>sorry, the date you entered cannot be recognized, please enter a valid date:
> 1 1 2009
>next day – 1/2/2009
>prior day – 12/31/2008
>please enter 'y' if you want to continue or 'Q' to quit: Q
>Thank you for using our date processor. Have a great day!
 

Poodles

I play with fire
Jul 22, 2006
16,757
0
0
43
Fort Worth, TX
Not really, as it all rolls over as they're all enhancements of C. It's more of a grammar difference than a language difference if you get what I mean...
 

CanadianLurch

New Member
Oct 14, 2008
117
0
0
Alberta
I took C++ a while back at university. Introduction to programming, my biggest suggestion is to write the program out on paper first, it seemed to help me out. I cant really remember much about the actual program, but if you need a hand with an algorithm or something I may be able to help you out....
 

Canuckrz

New Member
Jan 13, 2009
852
0
0
Calgary, Alberta
I did a c++ course in grade 12, it was easy at first but then it snowballed like crazy all of a sudden. I found it makes things a lot easier to find a sample program that does something similar and pick it apart to find out how it works than to read a book on it or even have someone explain it to you. There's quite a few forums where you can find those programs on.
 

mk3supra

New Member
Apr 22, 2005
231
0
0
Decatur, IL
www.supramania.com
I've been working on this and here is what I have so far. I think I am getting close but I am still having problems.

Code:
#include<iostream>
 
#define TRUE 1
#define FALSE 0
 
using namespace std;
 
class mydate{
   int day;
   int month;
   int year;
public:
   void readdate();
   int isLeapYear();
   string month2string();
   int exceedsDaysInMonth();
   void tommorow();
   void yesterday();
};
 
// Input date from user
void mydate::readdate(){
   cout << "Enter day (dd - 23 ) : ";
   cin >> day;
   cout << "Enter Month (mm - 04 ) : ";
   cin >> month;
   cout << "Enter year (yyyy - 2007 ) : ";
   cin >> year;
}
// make sure month days are correct
// return TRUE if days exceeds in a month
int mydate::exceedsDaysInMonth(){
  int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  if ( month < 1 || month > 12 || day > days[month-1])
     return TRUE;
  else
     return FALSE;
}
// convert numeric month into string
string mydate::month2string(){
   char *months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
   if ( exceedsDaysInMonth() ) {
    if ( ! (month < 1 || month > 12) )
       return months[month-1];
    else
       return "Unknown month";
   }
   else
    return "Unknown month";
}
// return TRUE if a year is leap
int mydate::isLeapYear(){
   if ( (year % 4)  != 0 ){
      return FALSE;
   }
   else if ( (year % 400)  != 0 ){
      return TRUE;
   }
   else if ( (year % 100)  == 0 ){
      return FALSE;
   }
   else
   {
      return FALSE;
   }
}
// validate and calculate tommorows date
void mydate::tommorow(){
  int td, tm, ty;
  int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  if ( year < 0 ){
       cerr << year << " is not a valid year" << endl;
       exit(1);
  }
  if ( exceedsDaysInMonth() ){
    if ( month == 2 && day == 29 ){
        if ( ! isLeapYear() ){
          cerr << year << " is not a leap year, so Feb doesn't have 29 days" << endl;
          exit(1);
        }
    }
    else
    {
      cerr << "Bad day value month - " << month << " (" << month2string();
      cerr <<  ") doesn't have " << day << " days "<< endl;
      exit(1);
    }
  }
  // calculate tommorow
 td=day;
 tm=month;
 ty=year;
 td++;
 if ( td > days[month-1]){
   td=1;
   tm++;
   if ( tm > 12 )
    { ty++; tm=1; }
 }
 cout << "Tommorow is " <<  td << "/" <<  tm << "/" <<  ty << endl;
}
}
  // calculate yesterday
 td=day;
 tm=month;
 ty=year;
 td--;
 if ( td > days[month-1]){
   td=1;
   tm--;
   if ( tm > 12 )
    { ty--; tm=1; }
 }
 cout << "Yesterday was " <<td << "/" <<  tm << "/" <<  ty << endl;
// main
int main(){
  mydate date;
  date.readdate();
  date.tommorow();
  return 0;
}
 

TobyCat

Member
Jul 14, 2006
470
0
16
Vancouver BC
you have some extra brackets in your code (line 102). leap year doesn't work, check your isLeapYear() code. For example, year 2000 was a leap year and 2000 modulus 4 is 0. So your check for for != 0 is incorrect if you're trying to find out if the supplied value (i guess it's a global /handslap) IS a leap year.

Also, be sure to follow the template. The instructor and markers are expecting the input to be of the example form, and looped. Put a loop in your main, watch for Y or Q. If you're having troubles 'parsing' the individual values from a single input string separated by spaces, look up string tokenizing...