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
  • Specifications: C++ Lab Lab01a: 1. Has an array of 5 elements that will accept the names...

    Specifications: C++ Lab 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...

  • 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,...

  • Using c++ Write a program that reads in a list of up to 25 first names...

    Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...

  • 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...

  • In C++ write a program: Your goal is to ask record the sales for 5 different...

    In C++ write a program: Your goal is to ask record the sales for 5 different types of salsa, the total sales, and the names of the highest and lowest selling products. Your program should have the following:  The name of the program should be Assignment7.  3 comment lines (description of the program, author, and date).  Create a string array that stores five different types of salsas: mild, medium, sweet, hot, and zesty. The salsa names should...

  • 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 (*)...

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