Question

In: Computer Science

CIS247C WEEK 2 LAB The following problem should be created as a project in Visual Studio,...

CIS247C WEEK 2 LAB

The following problem should be created as a project in Visual Studio, compiled and debugged. Copy your code into a Word document named with your last name included such as: CIS247_Lab2_Smith. Also include screen prints of your test runs. Be sure to run enough tests to show the full operation of your code. Submit this Word document and the project file (zipped).

The Zoo Class

This class describes a zoo including some general visitor information. We will code this class using the UML below. There is a video in the announcements on how to code a class from a UML diagram. There is also an example shown by the Exercise we complete together in the Week 2 class.

It is required to use a header file for your class definition that contains the private attributes and prototypes for the functions (no code in the header file!) Use a .cpp file for the code of the functions. Then create a separate .cpp file for the main function.

The file with the main function should have a documentation header:

/*

            Programmer Name: Your Name

            Program: Zoo Class

            Date: Current date

            Purpose: Demonstrate coding a simple class and creating objects from it.

*/

Coding the Zoo Class

Create a header file named: Zoo.h and a .cpp file named: Zoo.cpp. The easiest way to do this is to use the “Add Class” function of Visual Studio.

In the header file, put your class definition, following the UML as a guide. In the private access section, declare your variables. In the public access section, list prototypes (no code) for the two constructors, setters and getters and the other functions shown.

Zoo

-zooName : string   //example: Brookfield Zoo

-zooLocation : string     //city, state

-yearlyVisitors : int

-adultAdmissionCost : double

+Zoo()   //default constructor should zero numbers and set strings to “unknown”

+Zoo(name : string, place : string, visitors: int, cost : double)

+getName() : string

+getLoc() : string

+getVisitors() : int

+getAdmission() : double

+setName(name : string) : void

+setLoc(place : string) : void

+setVisitors(visitors : int) : void

+setAdmission(cost : double) : void

+printInfo() : void    //prints the name, location, visitors and adult admission cost

In the Zoo.cpp file, put the code for all the functions. Remember to put the class name and scope resolution operator in front of all function names.

Example setter:

void Zoo::setVisitors(int visitors) {yearlyVisitors = visitors;}

Example getter:

int Zoo:getVisitors() {return yearlyVisitors;}

In the .cpp file for the main function, be sure to add this to your includes:

#include “Zoo.h”

Here is some high level pseudocode for your main function:

main

            declare 2 string variables for the name and location

            declare int variable for the number of visitors

            declare double variable for the adult admission cost

            declare a Zoo object with no parentheses (uses default constructor)

            set a name for the Zoo (name of your choice such as “Brookfield Zoo”)

            set a location for the Zoo in the format: city, state (example: “Chicago, IL”)

            set the yearly number of visitors (any amount)

            set the adult admission cost (any amount)

            //use proper money formatting for the following

            use the printInfo() method to print the Zoo object’s information

            //Preparing for the second Zoo object

            //Suggestion: use getline(cin, variable) for the strings instead of cin

            Ask the user for a zoo name and input name into local variable declared above

            Ask the user for the zoo location and input the location into local variable

            Ask the user for the zoo yearly number of visitors and input into local variable

            Ask the user for the adult admission cost and input into local variable

            //Using the constructor with parameters to create an object

            declare a Zoo object and pass the four local variables in the parentheses

            use the printInfo() method to print the Zoo object’s information

end main function

SUBMITTING YOUR PROGRAM

When you are done testing your program, check that you have used proper documentation. Then copy and paste your code from Visual Studio into a Word document. Be sure to copy all three files. Take a screenshot of the console window with your program output. Paste this into the same document.

Save your Word document as: CIS247_Week2Lab_YourLastName.

Submit your Word document and also the properly zipped project folder.

C++ language

Solutions

Expert Solution

// Zoo.h

#ifndef ZOO_H
#define ZOO_H

class Zoo
{
private :
    //Declaring instance variables
    string zooName;
    string zooLocation;
    int yearlyVisitors;
    double adultAdmissionCost;
   
public :  
//Zero argumented constructor
Zoo();

//Parameterized constructor
Zoo(string name ,string place,int visitors,double cost);

// getters and setters
string getName();

string getLoc();

int getVisitors();
double getAdmission();
void setName(string name);

void setLoc(string place);

void setVisitors(int visitors);
void setAdmission(double cost);

//This function is used to display the contents of an object inside it
void printInfo() ;
};

#endif

________________________

// Zoo.cpp

#include <iostream>
using namespace std;
#include "Zoo.h"

Zoo::Zoo() //default constructor should zero numbers and set strings to “unknown”
{
    this->zooName="unknown";
    this->zooLocation="unknown";
    this->yearlyVisitors=0;
    this->adultAdmissionCost=0;
}

//Parameterized constructor
Zoo::Zoo(string name ,string place,int visitors,double cost)
{
      this->zooName=name;
    this->zooLocation=place;
    this->yearlyVisitors=visitors;
    this->adultAdmissionCost=cost;
}

// getters and setters
string Zoo::getName()
{
    return zooName;
}

string Zoo::getLoc()
{
   return zooLocation;
}

int Zoo::getVisitors()
{
   return yearlyVisitors;
}

double Zoo::getAdmission()
{
   return adultAdmissionCost;
}

void Zoo::setName(string name)
{
   this->zooName=name;
}

void Zoo::setLoc(string place)
{
   this->zooLocation=place;
}

void Zoo::setVisitors(int visitors)
{
this->yearlyVisitors=visitors;  
}

void Zoo::setAdmission(double cost)
{
   this->adultAdmissionCost=cost;
}

//This function is used to display the contents of an object inside it
void Zoo::printInfo()
{
   cout<<"Zoo Name :"<<zooName<<endl;
   cout<<"Zoo Location :"<<zooLocation<<endl;
   cout<<"No of Yearly Visitors :"<<yearlyVisitors<<endl;
   cout<<"Adult Admission Cost :$"<<adultAdmissionCost<<endl;
}

_____________________________

// main.cpp

#include <iostream>
using namespace std;
#include "Zoo.h"
int main()
{
   //Declaring variables
       string zooName;
    string zooLocation;
    int yearlyVisitors;
    double adultAdmissionCost;
   
    //Creating an instance of Zoo class
   Zoo z1;
  
   //calling the setters
   z1.setName("Zambo Zoo");
   z1.setLoc("CL");
   z1.setVisitors(150000);
   z1.setAdmission(120);
  
   z1.printInfo();
  
   //Getting the input entered by the user
   cout<<"\nEnter Zoo name :";
   getline(cin,zooName);
  
   cout<<"Enter Zoo Location :";
   getline(cin,zooLocation);
  
   cout<<"Enter yearly visitors :";
   cin>>yearlyVisitors;
   cout<<"Enter Adult Admission cost :$";
   cin>>adultAdmissionCost;
  
   cout<<endl;
  
      //Creating an instance of Zoo class
   Zoo z2(zooName,zooLocation,yearlyVisitors,adultAdmissionCost);
   z2.printInfo();
  
return 0;
}

_____________________________

Output:


Related Solutions

You should use Visual Studio to write and test the program from this problem.   Write a...
You should use Visual Studio to write and test the program from this problem.   Write a complete program with a for loop that (5 pts) uses proper variable types. (10 pts) uses a for loop to read in a real numbers exactly 8 times (10 pts) adds the number read in the loop to a running sum. (10 pts) Computes the average of the 8 numbers as a real number. (5 pts) Prints the correct result with 2 decimal places,...
Create a Visual Studio console project named exercise101. The main() function should prompt for the name...
Create a Visual Studio console project named exercise101. The main() function should prompt for the name of a text file located in the same directory as exercise101.cpp, and search for a word in the text file as follows: Enter text file name: Enter search word: The program should print the number of occurrences of the word in the file: occurrences of were found in If the file could not be opened then display: File not found Use Stream file I/O...
answer the following using C# Design and program a Visual Studio Console project in C# that...
answer the following using C# Design and program a Visual Studio Console project in C# that allows your user to enter a number. The program will examine the number to see if it is prime. If it is prime, it will print the next higher prime and the next lower primes to the console. If the number entered by the user is not prime, display a message to that effect. All code should be written by you. Do not copy/paste...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This project will be used to calculate the area of certain figures, like circles, squares and rectangles. So add a title to the Form. The Form Title should say “Area”. Also add 3 labels, 3 Buttons, 3 Textboxes and 3 RadioButtons. The 3 Buttons should be near the bottom of the Form and say “Calc Area”, “Clear” and “Exit”. Make sure to give all your...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project is a web projectb. Make sure it is using C#2. Add a new folder and name it Grades_Logic3. Inside this new folder create a new web form called “Grades”4. Add a label to hold text “Enter Grade”5. Add a text field in front of the label to receive the grade6. Add another label in a new line to display the text “Participation”7. Place a drop-down...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
Using Visual Studio Code (JavaScript) For this lab you must use a reasonable faceted search example,...
Using Visual Studio Code (JavaScript) For this lab you must use a reasonable faceted search example, each item must have at least three categorical attributes and at least one numeric attribute. Attributes such as ID, name etc do not count as categorical or numeric attributes. Exercise 1 (a) Define a class for your item that meets the above three categorical and one numeric attribute requirements. (b) Create a text file that contains at least 5 such records in CSV format....
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT