c++ - error C2228, error C2275 -


i new here. taking intermediate c++ programming @ devry online. using book c++ primer plus, , have been doing okay far. teacher has thrown bit of curve ball @ us. current assignment such:

create seconds class 1 variable: totalseconds (use type long). class should have 1 behavior (method): convert( ). behavior should receive following variables reference: days, hours, minutes, , seconds. method should convert totalseconds equivalent time in days, hours, minutes, , seconds. use symbolic constants in class represent number of hours in day, number of minutes in hour, , number of seconds in minute.

write short main program gets totalseconds (use type long). then, create seconds object. pass totalseconds seconds object using constructors or mutators. call convert( ) method, sending days, hours, minutes, , seconds arguments , reference. display days, hours, minutes, , seconds in main method. roads, here code:

main.cpp

/*gsp 125 intmed prgrmg c++/oop main.cpp*/ #include <iostream> #include <string> #include <conio.h> #include <fstream> #include "sec.h"   using namespace std;  int input = 0;  int main() {     system("title tick tack");     char choice1;     ofstream fout;     char filename[50];      cout << "save results file ? (y/n) : ";     (cin >> choice1).get();//make choice, y or n         if (toupper(choice1) == 'y')         {             cout << "enter filename(max 50 characters): ";             cin.getline(filename,50);//string file name             fout.open(filename);//makes text file chosen name         }         else             cout << "results not saved!\n\n";      // todo: add code here     cout << "enter number of seconds:";     long input;     cin >> input;      bravo alpha(long seconds,long minutes,long hours,long days,long years);     long breakdown = alpha.totalseconds(); //this gets error c2228: left of '.totalseconds' must have class/struct/union      cout << "\n\n" << input << " seconds = \n"<< breakdown << endl;     cout << year << day_remain << hour_remain << min_remain << seconds << endl;      // pause     cout << "\npress key continue...";     cin.sync();//clearscreen     _getch();//waitkey      // return environment variable     return 0; } 

time.cpp

// time.cpp #include "time.h"  // constructors bravo::bravo(void) {     seconds = 0;     minutes = 0;     hours = 0;     days = 0;     years = 0; }  bravo::bravo( long seconds, long minutes, long hours, long days, long years) {     seconds = seconds;     minutes = minutes;     hours = hours;     days = days;     years = years; }  // destructor bravo::~bravo(void) {}  // behaviors double bravo::totalseconds(void) {     long input = 0;     //convert minutes     long min = input / secpermin;     int sec = input % secpermin;     //convert hours     long hour = min / minperhour;     int min_remain = min % minperhour;     //convert days     long day = hour / hourperday;     int hour_remain = hour % hourperday;     //convert years     long year = day / daysperyear;     int day_remain = day % daysperyear;      return bravo; //this gets error c2275: 'bravo' : illegal use of type expression }  // accessors , mutators short bravo::getseconds(void)   {return seconds;}  void bravo::setseconds( long seconds )   {seconds = seconds;}  short bravo::getminutes(void)   {return minutes;}  void bravo::setminutes( long minutes )   {minutes = minutes;}  short bravo::gethours(void)   {return hours;}  void bravo::sethours( long hours )   {hours = hours;}  short bravo::getdays(void)   {return days;}  void bravo::setdays( long days )   {days = days;}  short bravo::getyears(void)   {return years;}  void bravo::setyears( long years )   {years = years;} 

time.h

// sec.h #ifndef bravo_h_ #define bravo_h_ #include <iostream>  // global constants const int daysperyear = 365; const int hourperday = 24; const int minperhour = 60; const int secpermin = 60; long int seconds = 0; long int minutes=0; long int hours=0; long int days=0; long int years=0; int min_remain=0; int hour_remain=0; int day_remain=0; int year=0;   // class definition class bravo {     private:     // accessors     short seconds;     short minutes;     short hours;     short days;     short years;      public:     // constructors     bravo(void);     bravo(long seconds, long minutes, long hours, long days, long years);      // destructor     ~bravo(void);      // behaviors     double totalseconds();      // accessors , mutators     short getseconds(void);     void setseconds( long seconds );     short getminutes(void);     void setminutes( long minutes );     short gethours(void);     void sethours( long hours );     short getdays(void);     void setdays( long days );     short getyears(void);     void setyears( long years );     short getmin_remain(void);     void setmin_remain( long min_remain );     short gethour_remain(void);     void sethour_remain( long hour_remain );     short getday_remain(void);     void setday_remain( long day_remain ); };  #endif 

error c2275: 'bravo' : illegal use of type expression
error c2228: left of '.totalseconds' must have class/struct/union

i have 2 errors noted, can not seem locate answers specify exact issues. believe went little overboard in .h file, attempting add accessors , constants, no avail. of deleted.

update: after following first answer provided managed solve previous errors. however, came across new one. converttodecimal line shown below has different error.

long seconds = 0, minutes = 0, hours = 0, days = 0; bravo alpha(input); float breakdown = alpha.converttodecimal(seconds, minutes, hours, days); // pass variables reference   //gets error c2660: 'bravo::converttodecimal' : function not take 4 arguments cout << "\n\n" << input << " seconds = \n" << breakdown << endl; cout << year << day_remain << hour_remain << min_remain << seconds << endl; 

i have tried changing resides in there, having no luck. changes have made converttodecimal, ended with

return converttodecimal;  //this closed error having 

bravo alpha(long seconds,long minutes,long hours,long days,long years); long breakdown = alpha.totalseconds(); //this gets error c2228: left of '.totalseconds' must have class/struct/union 

the first line doesn't make sense, shouldn't specifying type 'long' in front of arguments here. don't have instances of these variables being passed it. error on call totalseconds fails because 'alpha' wasn't created valid type result of problem. compile, try:

long seconds = 0, minutes = 0, hours = 0, days = 0; bravo alpha(input); alpha.convert(seconds, minutes, hours, days); // pass variables reference 

note had before isn't assignment asks for, you're supposed give single variable representing total number of seconds, , convert function should break down various components. change class definitions match.

someone else has commented

return bravo; //this gets error c2275: 'bravo' : illegal use of type expression 

line doesn't make sense since it's trying return type , not variable.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -