Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. //Structures:
  2. struct animal
  3. {
  4. char name[15];
  5. int age;
  6. char breed[15];
  7. int weight;
  8. char friendly[15];
  9. char description[200];
  10. };
  11. //Prototypes:
  12. void addAnimal(animal&);
  13. void displayMenu();
  14. void writeout(animal&);
  15. int main()
  16. {
  17. char choice;
  18. //Structure variables:
  19. animal myVar;
  20. //Function calls:
  21. do
  22. {
  23. displayMenu();
  24. cin >> choice;
  25. cin.ignore(100,'\n');
  26. if(choice == 'a' || choice == 'A')
  27. {
  28.  
  29. }
  30. else if(choice == 'b' || choice == 'B')
  31. {
  32. addAnimal(myVar);
  33. }
  34. else if(choice == 'c' || choice == 'C')
  35. {
  36.  
  37. }
  38. else if (choice == 'd' || choice == 'D')
  39. {
  40.  
  41. }
  42. else
  43. {
  44. cout << "Invalid choice!" <<endl;
  45. }
  46. writeout(myVar);
  47. return 0;
  48. }while(choice != 'a' || choice != 'A');
  49. }
  50. void addAnimal(animal& input)
  51. {
  52. cout << "What is the name of the animal?" <<endl;
  53. cin >> input.name;
  54. cin.ignore(100,'\n');
  55. cout << "How old is it? " <<endl;
  56. cin >> input.age;
  57. cin.ignore(100,'\n');
  58. cout << "What is the breed? " <<endl;
  59. cin.get(input.breed, 15, '\n');
  60. cin.ignore(100,'\n');
  61. cout << "Is it friendly or not friendly?" <<endl;
  62. cin.get(input.friendly, 15, '\n');
  63. cin.ignore(100, '\n');
  64. cout << "Please type a short description of the animal. " <<endl;
  65. cin.get(input.description, 200, '\n');
  66. cin.ignore(200,'\n');
  67. }
  68. void writeout(animal& input)
  69. {
  70. ofstream out;
  71. out.open("Inventory.txt");
  72. if(out)
  73. {
  74. out << input.name <<":" <<input.age <<":" <<input.breed << ":" <<input.friendly <<":" <<input.description <<":" <<endl;
  75. out.close();
  76. }
  77. }
  78.  
  79. void displayAll
  80. {
  81. ifstream in;
  82. in.open("Inventory.txt");
  83.  
  84. while(! open.eof())
  85. {
  86. getline(open);
  87.  
  88. }
  89.  
  90. void displayMenu()
  91. {
  92. cout << "A) Exit the program" <<endl;
  93. cout << "B) Add a new animal" <<endl;
  94. cout << "C) Search for a pet" <<endl;
  95. cout << "D) Display all the pets" <<endl;
  96. }
  97.  
  98. void search(something&, something&)
  99. {
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement