simulating a handheld texting device

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 4
Reputation: bit9435 is an unknown quantity at this point 
Solved Threads: 0
bit9435 bit9435 is offline Offline
Newbie Poster

simulating a handheld texting device

 
0
  #1
Apr 16th, 2009
I have a homework assignment that I'm stuck on...i have to make a program that works like text messaging on a cell phone. It uses three classes, keypad, display, and texter.
keypad - is the keypad. it allows the user to enter all alpha-numeric characters. the class handles input. it can include cin statements (like cin.getine) but no cout statements

display - it simulates a display on the texting device. It is responsible for the output and can only contain cout statments

texter - it's the "brain" It is responsible for orgainizng functions of the keypad and display classes so the user can send texts. the class should have one member variable which is a keyboard object and one member variable that's a display object. It is supposed to call functions on the objects to facilitate texting. This class should have no cin or cout statements

The code in main only does three things:
Declare a Texter object
Call a "menu" method on the Texter object
At the end of main, return 0

The texter screen should look like this:
Main Menu:
1. send Text Message
2. Turn off
Input your choice:

If the user chooses 1, the Texter should show
Input phone number: 1234567(the input)
Input Message: Hey! (the input)
Message sent successfully.

(Print main until the user chooses the second option)

Here is my code thus far:
  1. // keypad.h
  2.  
  3. #include <string>
  4. using namespace std;
  5.  
  6. class keypad
  7. {
  8. private:
  9. long int number;
  10. string message;
  11.  
  12. public:
  13. long int InputNumber();
  14. string InputMessage();
  15. };
  16.  
  17. // keypad.cpp
  18.  
  19. #include “keypad.h”
  20. #include <string>
  21. using namespace std;
  22. long int keypad::InputNumber()
  23. {
  24. cin >> number;
  25. return number;
  26. }
  27.  
  28. string keypad::InputMessage()
  29. {
  30. cin >> message;
  31. return message;
  32. }
  33.  
  34. // display.h
  35.  
  36. #include <string>
  37. #include “keypad.h”
  38. #include “keypad.cpp”
  39. using namespace std;
  40. class display
  41. {
  42. private:
  43. long int number;
  44. string message;
  45.  
  46. public:
  47. void InputPhone();
  48. void InputMessage();
  49. };
  50.  
  51. // display.cpp
  52.  
  53. #include “keypad.h”
  54. #include “keypad.cpp”
  55. #include <string>
  56. void display::InputPhone()
  57. {
  58. cout << “Input phone number: “;
  59. }
  60.  
  61. void display::InputMessage()
  62. {
  63. cout << “Enter your message: “;
  64. }
  65.  
  66. // text.h
  67.  
  68. #include “display.h”
  69. #include “display.cpp”
  70. #include “keypad.h”
  71. #include “keypad.cpp”
  72. class text
  73. {
  74. private:
  75.  
  76.  
  77. public:
  78. keypad key();
  79. Display disp();
  80. };
  81.  
  82. // text.cpp
  83.  
  84. #include “display.h”
  85. #include “display.cpp”
  86. #include “keypad.h”
  87. #include “keypad.cpp”
  88. #include “text.h”
  89.  
  90. void text::disp.InputPhone()
  91. {
  92.  
  93. }
  94.  
  95. void text::key.InputNumber()
  96. {
  97.  
  98. }
  99.  
  100. void text::disp.InputMessage()
  101. {
  102.  
  103. }
  104.  
  105. void text::disp.InputPhone()
  106. {
  107.  
  108. }
  109.  
  110. // textMain.cpp
  111.  
  112. #include “display.h”
  113. #include “display.cpp”
  114. #include “keypad.h”
  115. #include “keypad.cpp”
  116. #include <iostream>
  117. using namespace std;
  118.  
  119. text Texter

* i haven't started main yet. I want to get my classes done first
* one question, which files should I include in my classes...i don't know if i should include all of the ones i did include or if i only need the .cpp files

*any help is greatly appreciated
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 375
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: simulating a handheld texting device

 
0
  #2
Apr 16th, 2009
Header files such as string need to be included in the header file and in the .cpp file. We call these 2 files (header and .cpp) the definition of a class and its implementation when used to form a class.

If you want more help, ask more questions, but try to keep them specific.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: bit9435 is an unknown quantity at this point 
Solved Threads: 0
bit9435 bit9435 is offline Offline
Newbie Poster

Re: simulating a handheld texting device

 
0
  #3
Apr 17th, 2009
What goes in the text.cpp file with the variables? Is that where I put the objects then their function?

ie:key.InputPhone

but I'm not sure if I did those right...i don't know how to do it without cin or cout statements.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 375
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

Re: simulating a handheld texting device

 
0
  #4
Apr 17th, 2009
A class consists (most of the time) out of 2 parts: a definition and an implementation.

The definition defines the types and parameters of functions, as well as member variables. This is the header file.

The implementation gives code to the definition: it implements the definition.

Your assignment is to write an implementation given a specific definition: you're told what the objects should be able to do, but how they do it, how you implement those functions, is up to you.

Here is a simple example of a header file, it's implementation and it's use in a program. Note that the link uses void main() something you should never do.

http://functionx.com/cpp/examples/simpleclass.htm
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC