fork download
  1. /*
  2. " To"
  3. Date:5th January 2011
  4. Programmer:Fahad
  5. */
  6. #include <iostream>
  7. #include <string>
  8. using namespace std;
  9. class Persons //A class that will store the name,addresses and id numbers of the users
  10. {
  11. private:
  12. string name_;
  13. string address_;
  14. int id_number_;
  15.  
  16. public:
  17. static int count;//This is the count of the objects created
  18. Persons();
  19. void getData(int n);
  20. void displayData(int n);
  21. //~Persons();
  22. };
  23. static int count;//initializing the static member
  24. int main()
  25. {
  26. cout << "Enter Number Of Persons:";
  27. int n;//This is the number of objects that the user wants to make.
  28. cin >> n;
  29. Persons *ptr;//A pointer that will be used for the dynamic memory allocation.
  30.  
  31. /*Exception Handling*/
  32. ////////////////////////////////////////////////////////////////////
  33. try
  34. {
  35. //ptr=new [sizeof(Persons) * n];
  36. ptr=new Persons[n];
  37. }
  38. catch(bad_alloc xa)
  39. {
  40. cout<<"Sorry,Program Can Not Continue";
  41. cin.get();
  42. exit(1);
  43. }
  44. /////////////////////////////////////////////////////////////////////
  45. for(int i = 0; i< n; i++)
  46. {
  47. ptr[i].getData(n);
  48. }
  49. for(int j = 0; j< n; j++)
  50. {
  51. ptr[j].displayData( n );
  52. }
  53. cin.get();
  54. delete[] ptr;
  55. return 0;
  56. }
  57. /*Function Definitions*/
  58. Persons::Persons()
  59. (
  60. name_="";
  61. address_="";
  62. id_number_=0;
  63. count++;
  64. }
  65. void Persons::getData(int n)
  66. {
  67.  
  68. cout<<"Enter Name (Press '$' To Exit):";
  69. getline(cin,name_,'$');
  70. cout<<endl<<"Enter Address (Press '$' To Exit):";
  71. getline(cin,address_,'$');
  72. cout<<endl<<"Enter Identitiy Card Number:";
  73. cin>>id_number_;
  74.  
  75. }
  76. void Persons::displayData(int n)
  77. {
  78.  
  79. cout<<"Name:"<<name_;
  80. cout<<endl<<"Address:"<<address_;
  81. cout<<endl<<"Identitiy Card Number:"<<id_number_;
  82.  
  83. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:42: error: ‘exit’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:60: error: function ‘Persons::Persons()’ is initialized like a variable
prog.cpp:61: error: expected constructor, destructor, or type conversion before ‘=’ token
prog.cpp:62: error: expected constructor, destructor, or type conversion before ‘=’ token
prog.cpp:63: error: expected constructor, destructor, or type conversion before ‘++’ token
prog.cpp:64: error: expected declaration before ‘}’ token
prog.cpp:23: warning: ‘count’ defined but not used
stdout
Standard output is empty