Dynamic memory allocation homework

Reply

Join Date: Jul 2004
Posts: 1
Reputation: jehdo is an unknown quantity at this point 
Solved Threads: 0
jehdo jehdo is offline Offline
Newbie Poster

Dynamic memory allocation homework

 
0
  #1
Jul 24th, 2004
Objective
This assignment has been designed so that you understand the concept of using dynamic memory allocation in C++. After the completion of this assignment you should have a good grasp on:

o Array of Objects
o Use of new Operator for dynamic memory allocation in C++, for user-defined types.
o Use of delete Operator in C++, to free the memory allocated.
o Making your own header file and use it in your other program.
o Use of stream manipulator(s)

Assignment

Write a C++ program that tells the teams qualified for a tournament’s semi finals.
Your program should ask the user about the number of teams included in the tournament. After taking input from the user your program should dynamically allocate the memory for the number of teams.

Take the input of number of matches won and loss during previously played rounds by the teams.





The points will be granted to each team according to the match status as follows:

Match status Points
Won 4
Loss 0
Draw 2


A Team won a match will be granted 4 points, for draw 2 points will be given to each Team whereas no point is granted if a Team losses a match.

Your program should include a Class Team with the following Private data members.

o team_id

o noOfTeams

o country //of which country the team belongs to

o matches_played

o won

o loss

o point


Where the noOfTeams should be static and will be incremented on the creation of each object. The incremented value of noOfTeams should be assigned to team_id in the constructor’s definition. This is how it generates and assigns the team_id for each new Team.
Class Team should have the following public member function.

1. points()
This function will calculate the points of each Team after taking input from the user about the number of matches_played, won and loss during the tournament.

Your program should compare points attained by teams with each other and hence find out the top four teams and display them as a qualifying team for the semi finals.

Write the Setter functions to set or assign values to country, matches_played, won, loss and point of the Class Team.

Write the Getter functions to get value of country, matches_played, won, loss, and point of the Class Team.

Write constructor of the Class Team to initialize the data members.

Also write destructor for the Class Team.

Define the Class Team in a separate header file and include it into your main program.


Use stream manipulator, setw(5), to format your output.


How to create and include header file?


Define your class named Team in one file and save this file with a .h extension and you include this file as a Header File in your .cpp file


How you can create your own header file:

Create a folder with a name as “Assignment8�

Open your Dev c++ and write this program


EXAMPLE FOR CREATING YOUR OWN HEADER FILE:

Class Team
{
private:
//data members

public:

//member functions
};

o After writing this program save this file in a folder “Assignment8� as myHeaderFile.h, You can also compile the program to check errors..


Suppose if you create the folder “Assignment8� in Drive D:

The path will be “D:\Assignment8\myHeaderFile.h�.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Dynamic memory allocation homework

 
0
  #2
Jul 24th, 2004
Sorry, we are not your homework doers.

Anyway new and delete are tech info so here is an example

  1. int *n=NULL;
  2.  
  3. n = new int [10];
  4.  
  5. if(n==NULL)cout<<"Error:Not enough Memory";
  6.  
  7. delete[] n;

If you use a new statement then you should always delete it else your comp will soon run out of ram. Brrrr (Memory leaks).
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,318
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 229
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Dynamic memory allocation homework

 
0
  #3
Jul 24th, 2004
Doesn't new throw an execption instead of returning NULL unless you explicitly use 'new(std::nothrow)'?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC