Thread: C++ task

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2023
    Posts
    1

    C++ task

    Hello, I have a task in C++:
    My task is: Create a zoo structure to represent animals at a zoo. Let the structure contain the following data: number (integer), name, weight (in kilograms). Declare an array with three elements of the described zoo structure and test the following functions. Create the following features:
    • Function animal_create by which the keyboard is entered: number, name, weight(0.5 t)
    • Function output_animal to derive animal data
    • Function double_weight that doubles the weight of all animals
    What I have tried: view in file or:

    [COLOR=#24292F][FONT=-apple-system]
    Code:
    #include<iostream>
    #include<windows.h>
    #include<iomanip>
    #include<string.h>
    using namespace std;
    
    struct zoo{
    	int number;
    	char name [30];
    	double kg;
    	char push_back [30];
    };
    
    void animal_create (zoo[]){
    	cout<<"Number: ";
    	cin>>zoo.number;
    	cout<<"Name: ";
    	cin>>zoo.name;
    	cout<<"Weight: ";
    	cin>>zoo.kg;	
    }
    
    void output_animal(zoo[]){
    	cout<<"Number "<<setw(10)<<"Name "<<setw(10)<<"Weight "<<"\n";
    	cout<<zoo.number<<" "<<zoo.name<<" "<<zoo.kg<<"\n";
    }
    
    void double_weight(zoo[]){
    	int i;
    	for(int i=0; i<3; i++){
    		zoo[i].kg=zoo.kg*2;
    	}
    }
    
    int main(){
    	cout<<"Add animal: ";
    	cin>>zoo.push_back;
    	cout<<"Enter data: ";
    	int j;
    	for(int j=0; j<3; j++)
    	animal_create(zoo[i]);
    	return 0;
    }
    Attached Files Attached Files
    Last edited by Salem; 01-07-2023 at 11:47 PM. Reason: Inlined properly formatted code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Task 7.4, help
    By Franksy in forum C Programming
    Replies: 5
    Last Post: 12-18-2017, 06:01 PM
  2. Help me do my task
    By mykelis in forum C Programming
    Replies: 2
    Last Post: 09-10-2017, 08:38 AM
  3. Need help to do the big task
    By Steve Cao in forum Linux Programming
    Replies: 1
    Last Post: 07-16-2010, 02:01 PM
  4. Replies: 2
    Last Post: 12-31-2007, 11:40 AM
  5. Task Bar
    By cfrost in forum Windows Programming
    Replies: 1
    Last Post: 07-22-2004, 07:37 AM

Tags for this Thread