473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Need help with some c++ code.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. class Time
  8. {
  9. public:
  10.     void setHour(int);
  11.     void setMinute(int);
  12.     int getHour();
  13.     int getMinute();
  14.     void incrHour(int);
  15.     void incrMinute(int);
  16.     void printTime();
  17.     int addHr(){ return hr;};
  18.     int addMin() {return  min;};
  19.     Time(int hr, int min);//regular constructor
  20.     Time();//default constructor
  21.  
  22. private:
  23.     int hr, min;
  24. };
  25.  
  26. class ExtTime
  27. {
  28. public:
  29.     ExtTime(int hr, int min);
  30.     void timeZone(int, int);
  31.     void printTime();
  32. private:
  33.     string zone;
  34.     int hr, min;
  35. };     
  36.  
  37. void Time::setHour(int)
  38. {
  39. cout << "Enter the hour: ";
  40. cin >> hr;
  41. }
  42.  
  43. void Time::setMinute(int)
  44. {
  45.     cout << "Enter the minutes: ";
  46.     cin >> min;
  47. }
  48.  
  49. void Time::incrHour(int addHr)
  50. {
  51.         hr++;
  52.         if (hr==24)
  53.             hr= 0;
  54. }
  55. void Time::incrMinute(int addMin)
  56. {
  57.         min++;
  58.         if(min==60)
  59.         {
  60.         hr++;
  61.         min=0;
  62.         if(hr==24)
  63.             hr=0;
  64.         }
  65. }
  66.  
  67. void Time::printTime()
  68. {
  69.  cout << "In Eastern Standard Time the time is: ";  
  70.     if(hr < 10)  
  71.         cout << "0";  
  72.         cout << hr << ":";  
  73.     if(min < 10)  
  74.         cout << "0";  
  75.         cout << min;  
  76.  
  77. void ExtTime::timeZone(int, int)
  78. {
  79.     cout<<"Enter time zone (EST, PST, MST, CST):";
  80.     cin>> zone;
  81.     if (zone == "PST")
  82.         cout << "The time is: " << (hr-3) << ":" << min << endl;
  83.     if (zone == "EST")  
  84.         cout << "The time is: " << hr << ":" << min << endl;  
  85.     if (zone == "CST")  
  86.         cout << "The time is: " << (hr-1) << ":" << min << endl;  
  87.     if (zone == "MST")  
  88.         cout << "The time is: " << (hr-2) << ":" << min << endl;
  89.     else cout << "error" << endl;
  90.  }
  91.  
  92. int main()  
  93. {
  94.     Time myTime;
  95.     myTime.setHour();  
  96.     myTime.setMinute();
  97.     int hr = myTime.getHour();
  98.     int min = myTime.getMinute();
  99.     cout << "The hour is " << hr << " and the minute is " << min << endl;
  100.     myTime.printTime();
  101.     cout << endl;
  102.     myTime.addHr();
  103.     cout << "After adding 1 hour\n";
  104.     myTime.printTime();
  105.     cout << endl;
  106.     myTime.addMin();
  107.     cout << "After adding 1 minute\n";
  108.     myTime.printTime();
  109.     cout << hr;
  110.     cout << min;
  111.     cout << endl;
  112.     ExtTime newTime(hr,min);
  113.     newTime.timeZone(hr,min); 
  114. }
  115.  
These are the compiler errors:
1>c:\users\amber\documents\visual studio 2008\projects\week4_amber nelson\week4_amber nelson\week4_ambernelson.cpp(96) : error C2660: 'Time::setHour' : function does not take 0 arguments
1>c:\users\amber\documents\visual studio 2008\projects\week4_amber nelson\week4_amber nelson\week4_ambernelson.cpp(97) : error C2660: 'Time::setMinute' : function does not take 0 arguments

I am just starting to learn and I am a bit confused..
Mar 27 '11 #1
4 2419
weaknessforcats
9,208 Expert Mod 8TB
You have written functions to set the hour and set the minute. These functions take an int argument yet when you call these functions you provide no argument at all.
Mar 27 '11 #2
I don't think I am getting this.. How would I do this? Please explain..I'm stuck.
Mar 27 '11 #3
whodgson
542 512MB
I think he is suggesting that the functions setHour() and setMinute()should have int values in each parenthesis.
Mar 28 '11 #4
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. void Time::setHour(int) 
  2. cout << "Enter the hour: "; 
  3. cin >> hr; 
Your problem stems from this code. Here the Time::setHour function does not set the hour based an a value passed in. Instead the function asks for an int value which it uses to set the hour without verifying that the value obtained is valid.

Either remove the argument for Time::setHour(int) since you aren't using it or b) use it but do the cin before you call the function.
Mar 28 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cibulya Dmitriy | last post by:
Hi All, I want to catch the next MSSQL error in my SQL code with following continue calculations Server: Msg 17, Level 16, State 1, Line 1 SQL Server does not exist or access denied.
8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
2
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. I need a code sample for merge sort. Thank you. --Mark
2
by: Steve | last post by:
I have a combo box that I would like to expand or "drop down" programmatically. The Simple style won't work because I still need the control to contract or "roll up" after a selection is made, I...
10
by: HK | last post by:
With VB.NET 2005, and a Windows Form, running on a dual CPU box, I need to take a recordset (e.g. 100,000 records) and spawn a thread to handle an internet XML transaction routine for each of the...
1
by: Riyadh Hossain | last post by:
I am developing USPS shipping API for my site. All the work is going on testing phase. My site uses PHP/MySQL. Now I am working on USPS tracking/confirm. I can send request and get responses from...
8
by: JEO | last post by:
I have a Visual basic 3 App that I am converting to VBA in Microsoft Access 2003. The VB3 app successfully recolors a bitmap image with code using pixel locations when clicking on option buttons...
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
0
by: P.K Sahu | last post by:
hello there, i'm new to web service but i have a difficulty to understand web services. See, I created the webservice through the default template of visual studio & " hello world" but that does...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.