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.

Sorry, we are not your homework doers.

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

int *n=NULL;

n = new int [10];

if(n==NULL)cout<<"Error:Not enough Memory";

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

You have collected reviews from four movie reviewers where the reviewers are numbered 0-3. Each reviewer has rated six movies where the movies are numbered 100-105. The ratings range from 1 (terrible) to 5 (excellent).
The reviews are shown in the following table:
100
101
102
103
104
105
0
3
1
5
2
1
5
1
4
2
1
4
2
4
2
3
1
2
4
4
1
3
5
1
4
2
4
2
Write a program that stores this data using a 2D array. Based on this information your program should allow the user to enter ratings for any three movies. The program should then find the reviewer whose ratings most closely match the ratings input by the user. It should then predict the user’s interest in the other movies by outputting the ratings by the reviewer for the movies that were not rated by the user. Use the Cartesian distance as the metric to determine how close the reviewer’s movie ratings are to the ratings input by the user. This technique is a simple version of the nearest neighbor classification algorithm.
For example, if the user inputs a rating of 5 for movie 102, 2 for movie 104, and 5 for movie 105, then the closest match is reviewer 0 with a distance of sqrt((5-5)^2 + (2-1)^2 + (5-5)^2) = 1. The program would then predict a rating of 3 for movie 100, a rating of 1 for movie 101, and a rating of 2 for movie 103.

This article has been dead for over six months. Start a new discussion instead.