Help needed simple program!!

This is a discussion on Help needed simple program!! within the C++ Programming forums, part of the General Programming Boards category; can anyone help me to do this program??my little brother need my help but im not that good a c++ ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    6

    Help needed simple program!!

    can anyone help me to do this program??my little brother need my help but im not that good a c++ heres the problem

    *
    Define a class called Animal with the following data attributes
    Desc : array of 20 character
    Height : float
    Weight : float
    Define a class Bird that inherits from Animal class above wit hthe following attributes:
    Wingspan : float
    Your program should be able to store up to 10 BridRec records in an array called BirdsArray.

    Your program should at least perform the below operations

    - Add new birds records into BirdsArray
    - Display all birds record
    - Display the bird details with largeST winspan
    - Display the bird details with lowest winspan

    thats what it says to his take home problem thx

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.


    If you have any questions about this you may ask or you can contact one of our forum leaders:

    http://cboard.cprogramming.com/showgroups.php

    ----------

    once you have done so, look over the following code. if you're good at recognizing patterns, you'll be able to figure it out (it's working code, and is an example of the base class you'd need):
    Code:
    #ifndef __ANIMAL_H_
    #define __ANIMAL_H_
    
    #include<cstring>
    #include"Untitled1.h"
    
    cs cn
    {
        pbc:
            cn(noch dtc*in="",noch dtf h=0.0f,noch dtf w=0.0f);
            vd printstats();
        ptd:
            dtc desc[sz];
            dtf ht;
            dtf wt;
    };
    
    cn::cn(noch dtc*in,noch dtf h,noch dtf w)
    {
        strcpy(desc,in);
        ht=h;
        wt=w;
    }
    
    #endif
    edit: it works as long as you have the necessary (proprietary) file, or you fix the names. just FYI: I'll put as much effort into helping you as you put into it yourself.
    Last edited by major_small; 03-25-2005 at 03:55 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Thats great, i needed a homework type question like that to help me learn C#! That'll be ideal, thanks
    Couldn't think of anything interesting, cool or funny - sorry.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    wow ok thx i need to understand it 1st

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    hmmm is that a c++ code or a c# code???i only understand a little whats cs do???

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    \\can i code it like this im not too advance in c++ programming

    Code:
    #include <iostream.h>
    #include<string.h>
    #include<iomanip.h>
    #include<stdio.h>
    #include <conio.h>
    
    class animal{
    	char *Desc;
    	float Height;
    	float Weight;
    	public:
    	void setanimal (char *desc, float height, float weight){
    	Desc = new char[strlen(desc)+1];
    	strcpy(Desc, desc);}
    	};
    
    class bird: public animal{
    	float Wingspan;
    	public:
    	void setbird (float wingspan){Wingspan = wingspan;}
    	};
    \\but i dont know how to add an array of object to it lol so that i can add 20 information and how to gety the highets and lowest wingspan

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    6

    heres the progresss

    ok i got everything to add a record and display what have i added now the real problem is how do i get them to show the largest and smallest wingspan??heres my code:

    Code:
    #include <iostream.h>
    #include<string.h>
    #include<iomanip.h>
    #include<stdio.h>
    #include <conio.h>
    
    class animal{
    	public:
    	char *Desc;
    	float Height;
    	float Weight;
    	char *getDesc(void){return Desc;}
    	float getHeight(void){return Height;}
    	float getWeight(void){return Weight;}
    
    	void setanimal (char *desc, float height, float weight){
    	Desc = new char[strlen(desc)+1];
    	strcpy(Desc, desc);
    	Height = height;
    	Weight = weight;}
    
    	void PrintAllInfo(){
    		cout<<"Desc: "<<getDesc()<<endl;
    		cout<<"Height : "<<getHeight()<<endl;
    		cout<<"Weight : "<<getWeight()<<endl;
    		}
    	};
    
    class bird: public animal{
    	public:
    	float Wingspan;
    	float getWingspan(void){return Wingspan;}
    	void setbird (float wingspan){Wingspan = wingspan;}
    	void PrintInfo(){
    		cout<<"Wingspan: "<<getWingspan()<<endl;}
    	};
    
    
    
    
    void main(void) {
    int choice;
    bird BirdRec[9];
    int x = 0,countera = 0;
    char *Desc;Desc = new char[20];
    float height,weight,wingspan;
    do {
    clrscr();
    cout<<"[1]Add new Bird Rec"<<endl;
    cout<<""<<endl;
    cout<<"[2]Display all Bird's Record"<<endl;
    cout<<""<<endl;
    cout<<"[3]Display the bird with the largest winspan"<<endl;
    cout<<""<<endl;
    cout<<"[4]Display the bird with the smallest winspan"<<endl;
    cout<<""<<endl;
    cout<<"[5]Exit"<<endl;
    cout<<""<<endl;
    cout<<"Please Enter a number: ";
    cin>>choice;
    
    
    switch(choice){
    case 1:
    	int choose;
    		do{
    		cout<<"Enter Birds Name: ";
    		gets(Desc);
    		cout<<"Enter height: ";
    		cin>>height;
    		cout<<"Enter weight: ";
    		cin>>weight;
    		cout<<"Enter wingspan: ";
    		cin>>wingspan;
    		BirdRec[x].setbird(wingspan);
    		BirdRec[x].setanimal(Desc,height,weight);
    		cout<<"Enter another Record?[1]Yes / [2]No";
    		cin>>choose;
    		x = x + 1;
    		}while(choose != 2);
    break;
    case 2:
    		int counter, y;
    		y = x - 1;
    		clrscr();
    		if (y < 0) {
    		cout<<"There is still no data of any Bird Recorded"<<endl;}
    		else {
    		for (counter = 0;counter <= y;counter=counter+1){
    		BirdRec[counter].PrintAllInfo();
    		BirdRec[counter].PrintInfo();
    		cout<<""<<endl;
    		}}
    		;
    		getch();
    
    
    break;
    
    case 5:
    	countera = 2;
    
    }
    
    }while(countera != 2);
    i use switch to do the menu thing and i hope to do the case 3 and 4 for the largest and smallest wingspan thx

  8. #8
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    jigen, I notice you have 3 posts in the space of 17 minutes, not to mention a total of 4 consecutive posts. Please learn to use the board's edit feature if you need to change part of a post. What you are doing may be considered 'bumping', and is against forum rules. This forum also carries a very negative attitude towards homework questions. You can feel free to ask for help with an assignment, but you need to give everything your best try before coming to us. You can't expect someone to dohalf your assignment for you.

    I suggest you use the search feature major_small recommended for you. There have been many threads where people need to find the minimum and maximum value out of a series of numbers.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    oh ok thx for reminding me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  4. Mystery bug in simple program? - I am beginner
    By archie123 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2005, 07:23 AM
  5. Help with small simple program
    By Sonor in forum C Programming
    Replies: 5
    Last Post: 04-02-2005, 06:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21