Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Structures:
- struct animal
- {
- char name[15];
- int age;
- char breed[15];
- int weight;
- char friendly[15];
- char description[200];
- };
- //Prototypes:
- void addAnimal(animal&);
- void displayMenu();
- void writeout(animal&);
- int main()
- {
- char choice;
- //Structure variables:
- animal myVar;
- //Function calls:
- do
- {
- displayMenu();
- cin >> choice;
- cin.ignore(100,'\n');
- if(choice == 'a' || choice == 'A')
- {
- }
- else if(choice == 'b' || choice == 'B')
- {
- addAnimal(myVar);
- }
- else if(choice == 'c' || choice == 'C')
- {
- }
- else if (choice == 'd' || choice == 'D')
- {
- }
- else
- {
- cout << "Invalid choice!" <<endl;
- }
- writeout(myVar);
- return 0;
- }while(choice != 'a' || choice != 'A');
- }
- void addAnimal(animal& input)
- {
- cout << "What is the name of the animal?" <<endl;
- cin >> input.name;
- cin.ignore(100,'\n');
- cout << "How old is it? " <<endl;
- cin >> input.age;
- cin.ignore(100,'\n');
- cout << "What is the breed? " <<endl;
- cin.get(input.breed, 15, '\n');
- cin.ignore(100,'\n');
- cout << "Is it friendly or not friendly?" <<endl;
- cin.get(input.friendly, 15, '\n');
- cin.ignore(100, '\n');
- cout << "Please type a short description of the animal. " <<endl;
- cin.get(input.description, 200, '\n');
- cin.ignore(200,'\n');
- }
- void writeout(animal& input)
- {
- ofstream out;
- out.open("Inventory.txt");
- if(out)
- {
- out << input.name <<":" <<input.age <<":" <<input.breed << ":" <<input.friendly <<":" <<input.description <<":" <<endl;
- out.close();
- }
- }
- void displayAll
- {
- ifstream in;
- in.open("Inventory.txt");
- while(! open.eof())
- {
- getline(open);
- }
- void displayMenu()
- {
- cout << "A) Exit the program" <<endl;
- cout << "B) Add a new animal" <<endl;
- cout << "C) Search for a pet" <<endl;
- cout << "D) Display all the pets" <<endl;
- }
- void search(something&, something&)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement