Question

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

Solution(s):

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

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

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

  • C++ programming Phone Book Create a class that can be used for a Phone Book. The...

    C++ programming Phone Book Create a class that can be used for a Phone Book. The class should have attributes for the name and phone number. The constructor should accept a name and a phone number. You should have methods that allow the name to be retrieved, the phone number to be retrieved, and one to allow the phone number to be changed. Create a toString() method to allow the name and number to be printed. Write a program that...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

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

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

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

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