Question

Specifications: Lab01a: 1. Has an array of 5 elements that will accept the names of up...

Specifications:

Lab01a:

1. Has an array of 5 elements that will accept the names of up to five animals

2.Has an array of 5 elements that will store a list of up to five animal ages

3.Accepts the name(s) and age(s) of one to five animals. Input should cease at the fifth entry, or when the user enters the word STOP, stop or Stop. (5 points)

The animal names can be one or more words. Assume at least one animal will be entered.

4.Display the following (5 points)

a.Display your name and major (See screenshots below)

b.Displays the list of animals and their ages. Each animal name must have a corresponding age.

Create program

Lab01b that:

5.Has a Vector that will accept and store the animal names

6.Has a Vector that will accept and store the animal ages

7.Accepts the name(s) and age(s) of one to five animals. Input should cease at the fifth entry, or when the user enters the word STOP, stop or Stop. (5 points)

You MUST use the push_back method when adding items to the vector. The animal names can be one or more words. Assume at least one animal will be entered.

Display the following (5 points)

a. Display your name and major (See screenshots below)

b. Displays the list of animals and their ages. Each animal name must have a corresponding age.

This program should be done in c++. The program should use loops to check stop, Stop, and STOP. Don't use break.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

ANSWER:

CODES:

LAB1A:

#include<bits/stdc++.h>
using namespace std;


int main()
{
string animals[6]; //array of strings
int ages[6]; //array of integers
int c=1;
cout<<"Starting Lab01"<<endl;
for(int i=1;i<=5;i++) //this will iterate five times and takes input of animals and ages
{
    cout<<"Enter animal "<<i<<" name:";
    cin>>animals[i];
    if(animals[i]=="Stop" || animals[i]=="STOP" || animals[i]=="stop") //if animals==stop then it will break;
    {
        break;
       }
    cout<<"Enter animal "<<i<<" age:";
    cin>>ages[i];
    c++; //counter if animal==stop statement then it should only print till that
   }
   cout<<endl;
   cout<<endl;
   cout<<"lab01 by Clen Kadiddlehopper Computer Science"<<endl;
   cout<<endl;
   cout<<"Animal"<<endl;
cout<<"# name age"<<endl;
   for(int i=1;i<c;i++)
   {
   cout<<i<<" "<<animals[i]<<" "<<ages[i]<<endl; //printing till counter the animal names and ages
   }
}

LAB01B:

code:

#include<bits/stdc++.h>
using namespace std;


int main()
{
vector<string>animals; //vector of animals
  
vector<int>ages; //vector of ages

string s;
int a;
int c=0;
cout<<"Starting Lab01"<<endl;
for(int i=0;i<5;i++) //iterate five times and takes the input
{
   
    cout<<"Enter animal "<<i+1<<" name:";
    cin>>s;
    animals.push_back(s); //pushing strings into vector of animals
    if(animals[i]=="Stop" || animals[i]=="STOP" || animals[i]=="stop") //if animals==stop then it will break;
    {
        break;
       }
    cout<<"Enter animal "<<i+1<<" age:";
    cin>>a;
    ages.push_back(a); //pushing numbers into vector of ages
    c++; //counter if animal==stop statement then it should only print till that
   }
   cout<<endl;
   cout<<endl;
   cout<<"lab01 by Clen Kadiddlehopper Computer Science"<<endl;
   cout<<endl;
   cout<<"Animal"<<endl;
cout<<"# name age"<<endl;
   for(int i=0;i<c;i++)
   {
   cout<<i+1<<" "<<animals[i]<<" "<<ages[i]<<endl; //printing till counter the animal names and ages
   }
}

HOPE IT HELPS YOU

PLEASE RATE THUMBSUP

Add a comment
Know the answer?
Add Answer to:
Specifications: Lab01a: 1. Has an array of 5 elements that will accept the names of up...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • Using Java Create an application that creates and displays a list of names using an array....

    Using Java Create an application that creates and displays a list of names using an array. Then modify the application to create and use a list of numbers. Console for the names application Please enter a name or type “exit” to quit: Diane Please enter a name or type “exit” to quit: Joe Please enter a name or type “exit” to quit: Greta Please enter a name or type “exit” to quit: Henry Please enter a name or type “exit”...

  • write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last...

    write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last name and first name of the owner). Ask the user to input up to 10 Contacts (It may be less. The user should have the ability to stop inputting Contacts whenever he wishes). 3.This class will store a list of Contacts in a stack allocated array of default capacity 10. 4.You must be able to add new contacts to a list, delete old contacts,...

  • Write a program that has an array of at most 50 strings that hold people’s names...

    Write a program that has an array of at most 50 strings that hold people’s names and phone numbers. You can assume each string’s length is no more than 40. You may make up your own strings, or use the following: "Becky Warren, 555-1223" "Joe Looney, 555-0097" "Geri Palmer, 555-8787" "Lynn Presnell, 555-1212" "Holly Gaddis, 555-8878" "Sam Wiggins, 555-0998" "Bob Kain, 555-8712" "Tim Haynes, 555-7676" "Warren Gaddis, 555-9037" "Jean James, 555-4939" "Ron Palmer, 555-2783" The program should ask the user...

  • The goal of this homework is to write a small database system for an Animal Shelter....

    The goal of this homework is to write a small database system for an Animal Shelter. This is a no-kill shelter like the one just west of the Addition Airport. You will accept animal “donations” to the shelter, but mostly only dogs and cats. (But yes, there may be the occasional hamster or other nondog, non-cat animal donation.) At present, all we need to do is write the skeleton of a database that will track all the animals in the...

  • in c++ Program 1 Write a program that sorts a vector of names alphabetically using the...

    in c++ Program 1 Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions I. void selSort (vector string &v: sorts the vector using selection sort 2. void display (const vector <string & v): displays the vector contents . int binSearch (const vector <ing& v, string key): searches the vector for a key returns the...

  • Question 1 and 2 ... Visual Basic dlear the contents of the textboxes. Do not accept...

    Question 1 and 2 ... Visual Basic dlear the contents of the textboxes. Do not accept a negative value for any of the inputs. Your application should have a button clear and utilize a separate procedure to e an application that prompts the user to enter today's sales for five program should then display a simple bar graph comparing each 2. Creat stores. The stores sales. Create each bar in the bar grah by displaying a row of asterisks (*)...

  • Use python write Thank you so much! pets.txt dog alyson 5.5 cat chester 1.5 cat felice...

    Use python write Thank you so much! pets.txt dog alyson 5.5 cat chester 1.5 cat felice 16 dog jesse 14 cat merlin 5 cat percy 12 cat puppet 18 to_transfer.txt cat merlin 5 cat percy 12 intake.txt bird joe 3 cat sylvester 4.5 the website is https://www2.cs.arizona.edu/classes/cs110/spring17/homework.shtml Welcome to animal shelter management software version 1.0 Type one of the following options adopt a pet adopt intake add more animals to the shelter list. display all adoptable pets quit exit the...

  • Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the...

    Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the names of the teams that won the Super Bowl from 1967 through 2019. Write a program that repeatedly allows a user to enter a team name and then displays the number of times and the years in which that team won the Super Bowl. If the team entered by the user has never won the Super Bowl, report that to the user instead. For...

  • C++ I need a program that will read a list of names from a data file and store them in an array. You will then sort the array by last name using a quicksort, and display the results, one name per line...

    C++ I need a program that will read a list of names from a data file and store them in an array. You will then sort the array by last name using a quicksort, and display the results, one name per line.Each line has a first name and a last name.The file has 40 names in it right now, but the array should be able to accommodate up to 50 names.txt***************************************************** Barbara Wright Ian Chesterton Steven Taylor Sara Kingdom Dodo...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT