Class and Object Problem

Hi, please could somebody give some guidance with this C++ question, I have done most of the code I just cant get the program to run.

Q. Create a class called Prompt. Pass a prompting string to a constructor. Have the constructor display the string and then expect the input of an integer. Store this value in a private variable called count. When an object of type Prompt is destroyed, ring the computer bell (output ‘\a’) as many times as the user entered in response to the request for an integer.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Prompt.h" // gives us access to the Prompt class
#include <iostream> // gives us access to simple input and output
using namespace std; // don't worry about namespaces yet

void main()  {
	// dummy variable for pausing the program
	string pause;

    // create an instance of a rings object
    Prompt rings("");
	

    // uses the setter method initialise the rings
    rings;
	

	// uses the getter method for accessing accountName
	cout << "How many times would you like to ring my bell: \n";
	cout << rings.getrings() << endl;

	cin >> pause;

}//end of main 


promptclass.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "Prompt.h" // gives access to the declarations

Prompt::Prompt(void)
{
    ringAmount = "";
    rings = 0.0;
}

Prompt::Prompt(string numberIn)
{
    ringAmount = numberIn;
    rings = 0.0;
}

Prompt::~Prompt(void)
{
	// nothing do to
}

string Prompt::getringAmount(void)
{
return ringAmount;
}


double Prompt::rings(void)
{	
	return rings;
}

void Prompt::deposit(double amountIn)
{
	rings = rings;
}


prompt.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once
#include "string"
using namespace std; // don't worry about namespaces for now

class Prompt
 {
 private:

	// private attributes cannot be accessed directly. 
	string ringAmount;
	double rings;

	
public:

	//constructor

	Prompt(string value);
	Prompt(void); 

 
	//destructor

	~Prompt(void);

	// accessor methods (getters)
	string getringAmount(void);
	double getrings(void);
}
Last edited on
Code Formatted!!!
What is you question .. do you want the code to ring the bell . .
You dont have the deposite function in you header class declaration .
Last edited on
May I ask what program do you use to code ? I think I saw a few errors... depending on what developer program you use ... (If you are using either Code::Blocks or BorlandC++ you might be ok, if your using other code program like DevC++ , MinGW, then your code is wrong...)
Seriously, this guy needs a prayer!!
void main()
This is incorrect and a good compiler will not compiler it. main() returns an int.

You're missing a semi-colon at the end of your class declaration.

You've defined a function double Prompt::rings(void) without having declared it in your class declaration.
Likewise void Prompt::deposit(double amountIn)

In C++, we don't write someFunction(void) - we write someFunction() .

rings = rings;
What exactly is that for?

1
2
  // uses the setter method initialise the rings
    rings;

This does nothing. It certainly does not call a setter method.

1
2
 // create an instance of a rings object
    Prompt rings("");

No, it creates an object of Prompt type, named rings. That's a really bad name for the object, given that it contains a variable also called rings. You're just going to confuse yourself.
Last edited on
Using Visual Studio, gotta get the program to ring the \a bell however many times the user inputs. Thanks for the trolling BTW!!
It seems that you are not even trying.
When an object of type Prompt is destroyed, ring the computer bell
When an object is destroyed, the destructor is called.

¿When is cout destroyed?
Wow, it seems that all programmers are the same....

Cocky wankers that are only out to prove that they know more than you about programming!

I come on to a forum for advice and all i receive is abuse, trolling and put downs!

pearce007 ''I have only been programming 3 months and could do with some guidance''

Programmer ''This forum is for people who know everything about programming go and RTFM''

Oh and ne555, I spent 6 hours trying to write this code yesterday, for someone that isnt trying 6 hours is a long time!!

Rant Over

Thanks but no thanks!
Last edited on
Then you were reading the wrong problem.

The problem wrote:
Create a class called Prompt.
Pass a prompting string to a constructor.
Have the constructor display the string and then expect the input of an integer.
Store this value in a private variable called count.
When an object of type Prompt is destroyed, ring the computer bell (output ‘\a’) (yadda yadda)

¿Why the hell is there a Prompt::deposit() method?
¿What do you need the getters for?
I suppose that rings is the counter variable. ¿Why is it double?
You are doing nothing that you were asked for. The constructor and destructor are empty.

Six hours coding is no joke, especially under the influence of alcohol.
You should have read some theory. Or kick the ball
Last edited on
Topic archived. No new replies allowed.