|
i got this as my class assignment. i am having hard time figuring this out im new to programming scene so please help...the instructions go as following:
The New Telephone Company has the following rate structure for long-distance calls:
The regular rate for a call is $0.20 per minute.
Any call started at or after 6:00 p.m. (1800 hours) but before 8:00 a.m. (800 hours) is discounted 50 percent for off-peak hours.
Any call longer than 60 minutes receives a 15 percent discount on it cost (after off-peak hours discount is subtracted)
All calls are subject to a 4 percent federal tax on their final cost.
Write a program that reads
The start time for a call based on a 24-hour clock
(Note: you only need start time and don’t need the end time)
The length of the call (number of minutes).
Your program needs to check for illegal inputs
Number of minutes cannot be 0 or negative
The start time for a call cannot be less than 0 or greater than 2359. Also the start time cannot be
1263, 885, 2099, etc… (WHY?)
If there is any error, print the appropriate error message and end the program by return -1.
(Note: you can put a return statement anywhere inside your program, when return statement is executed, the program will end.)
Finally, the program will print the following results:
The gross cost (before any discount or tax)
The net cost (after discounts are deducted)
The Final cost (with tax added).
Test your program with all scenarios. Illegal minutes, illegal starting time, regular call under an hour, regular call over an hour, off-peak call under an hour, off-peak call over an hour, 60 minute off-peak call,
60 minute peak time call………….etc………..
any help would be appreciated.
|
|
|
|
|
calizdesi wrote: The start time for a call cannot be less than 0 or greater than 2359. Also the start time cannot be
1263, 885, 2099, etc… (WHY?)
Those value limitations exist because they don't exist on a 24h clock. You should have noticed that 2359 is actually 23:59, that's why there cannot be any values larger then that. The other ones are 12:63, 8:85 and 22:99, and, has you know, each hour as 60 minutes, so it makes no sence talking about 63, 85 or 99 minutes.
I think you should write a function that converts an integer value (such as the ones provided by you) into its time equivalent. Given an input of 1263, the function could, for instance, return a structure containing those values separately.
struct sTime {
int Hours, Minutes;
};
And then check its values. Something like this:
struct sTime TimeLine;
int StartTime;
scanf( "%d", &StartTime );
TimeLine = IntToTime( StartTime );
So IntToTime would return a structure containg the values TimeLine.Hours == 12 and TimeLine.Minutes == 63. You may now validate them very easly:
if ( StartTime.Hours < 0 || StartTime.Hours > 23 || StartTime.Minutes < 0 || StartTime.Minutes > 59 )
If this statement is true, then you an invalid input.
As far as I can tell, the rest of the application is all about calculations, so I think this was your biggest stumbling problem (right?). Try it again.. If you can't let me know
regards [[]]
hint_54
|
|
|
|
|
first of all i would like to thank you for your help.i am very very very new to this so is there any way you can type the whole code or some important part of the code for me. ill be very grateful to you. thanks and regards.
-- modified at 18:52 Wednesday 15th March, 2006
|
|
|
|
|
hint_54
-- modified at 19:56 Wednesday 15th March, 2006
Have you already tried?
|
|
|
|
|
I got an error for the following codes regarding ifstream:
#include <fstream>
#include <afxtempl.h>
class CMyclass: public CObject
{
public:
CMyclass();
DECLARE_SERIAL (CMyclass)
virtual ~CMyclass();
public:
//
// other methods here
//
BOOL OnLoadData(ifstream& inFile); // load data from a file stream
};
When compile this header, I got "error C2061: syntax error : identifier 'ifstream'" message. I am wondering why 'ifstream' is NOT defined in <fstream> (it should be as msdn says).
Thanks.
-- modified at 16:31 Tuesday 14th March, 2006
|
|
|
|
|
If you modify your post, changing the <s to <s we might be able to figure out what your problem is.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks for that hint. Now I think the original post has been modified as it should.
|
|
|
|
|
ifstream is in the std namespace, either use std::ifstream or using namespace std; .
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
|
i am using VC++6 and MFC and using dialogs. I have a button that when clicked starts a method which creates an instance of a class, this object is then used to connect to the database and also does querys. how can i make this object seen by other methods and dialogs?
can this object be created globally? or what is best practice?
|
|
|
|
|
Its best practice to have as little global objects as possible.
There is at least on global object theApp (the application) which can be accessed through the
function AfxGetApp() which returns a pointer to the application object.
You can make you database access class a member of the application class. Then you can access this class through the Application pointer from anywhere in your application.
codito ergo sum
|
|
|
|
|
many thanks for your repply
could you further explain this with a code example please??
regards
|
|
|
|
|
Too many globals are indeed bad, but that doesn't mean any use of globals is bad. Assuming you want a global variable here's one way to do it in C++:
extern int *g_pIntPointer;
int *g_pIntPointer = NULL;
Now in any file where you add a #include "TheDotHFile.h" your can access you global.
There are other choices like putting the variable in a class and making it static . If you explain you situation more thoroughly I'm sure you can spark off a debate about the pros and cons of the various techniques.
Steve
|
|
|
|
|
what about putting your object/pointer in stdafx.h file.. which is included in almost easch file in mfc application.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
what about putting your object/pointer in stdafx.h file.. which is included in almost easch file in mfc application... i.e. give a dummy declaration of variable with extern keyword there and declare it in the place you actually using it...
i generally use Singleton class for this ... as it gurantee me a single object acceciable through out the project
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
im getting a bit confused now!
to further exlpain. i have a basic MFC dialog app that was created using the wizard. i want to connect to a database and execute querys, i am using a wrapper for this (mysqlwrapp). to make an object of the dbconnection class i use the following in a method that is invoked by a click of a button.
CSQLConnection m_conn; //create object
m_conn.Open(_T("localhost"), _T("salaries"), _T("root"), _T("root")); //connect
then in another method i want to execute the following, but it cant see the m_conn object. this new object allows querys to database
CSQLResult res(m_conn);
res.Query(_T("SELECT Name FROM house"));
to create these objects the "MySQLWrapp.h" is included in the dialog where the objects are created and used.
so what is the best way to make the m_conn object global. could you please give example code on where and how as most of this is new to me. thanks
|
|
|
|
|
The "m_" wart is normally used to denote a class member variable and not a local variable as you’re using it. Follow these steps:
1. Remove the CSQLConnection m_conn; from the function.
2. Add it to your class definition. i.e.
class CYourDialog : public CDialog
{
public:
protected:
private:
CSQLConnection m_conn;
};
Notice I added the member variable as private , this is good form - As a rule of thumb always apply the most restrictive access permissions possible. You can always relax them later if need be.
Now you can access the variable "m_conn" anywhere in that class. It's not a global however as it can't be accessed from other classes or global functions.
Only use the "m_" wart on member variables (variables declared in the class definition) or else you'll confuse people.
Steve
|
|
|
|
|
|
hello,
how can i detect a hyperlink in word file?
thanks for any help
|
|
|
|
|
I'm trying to use the shell function SHGetPathFromIDList but not having luck constructing the first parameter properly. It requires an item identifier list and in my case, I'm needing the path to just the 'My Documents' folder. If someone can post an example or a link to an example that explains how to create this list with just that entry in it and how it's to be freed, if necessary, that would help me out. Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
BAD DAY FOR: Friendly competition, as Ford Motor Co. declared the employee parking lot at its truck plant in Dearborn, Mich., off limits to vehicles built by rival companies. Workers have to drive a Ford to work, or park across the street. [CNNMoney.com]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
|
Thanks Mike. That's going to work much better.
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
BAD DAY FOR: Friendly competition, as Ford Motor Co. declared the employee parking lot at its truck plant in Dearborn, Mich., off limits to vehicles built by rival companies. Workers have to drive a Ford to work, or park across the street. [CNNMoney.com]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Looks like Michael's answered your immediate question, but for future reference, here's some code that gets the Application Data folder - just change the CSIDL_COMMON_APPDATA to whatever you want.
CString strCommonDataStorageFolder;
LPITEMIDLIST pidl;
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_APPDATA, &pidl)))
{
LPMALLOC lpMalloc;
if (::SHGetMalloc(&lpMalloc) == NOERROR)
{
TCHAR szPath[MAX_PATH];
if (SHGetPathFromIDList(pidl, szPath))
strCommonDataStorageFolder = szPath;
lpMalloc->Free(pidl);
lpMalloc->Release();
}
}
|
|
|
|
|
Thanks very much, Graham. The example you provided is exactly what I was after, but I'm also going to look into Mike's suggestion too. Appreciate the help.
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
BAD DAY FOR: Friendly competition, as Ford Motor Co. declared the employee parking lot at its truck plant in Dearborn, Mich., off limits to vehicles built by rival companies. Workers have to drive a Ford to work, or park across the street. [CNNMoney.com]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
For some reason, when I compare two identical double values, its failing.
double val = func->GetValue() // returns a double
double val1 = func2->GetOldVal() // returns a double
if (val != val1)
doFooA()
else
doFooB().
In my case, val == val1, but its passing and calling doFooA(). I've tried 'if ( (double) val != (double) val1) )' and 'if ((float) val != (float) val1)'. Although I know the latter will lose precision, I"m trying anything.
Any ideas why this is happening?
TIA
-C
|
|
|
|