We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More


Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

How to Add New Discussion in Study Group ? Step By Step Guide Click Here.

 

Please read the following instructions carefully before submitting assignment.

It should be clear that your assignment will not get any credit if:

 

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)
  • Code file is in any other format than .CPP

 

Objective:

 

The objective of this assignment is to learn, practice and understand practical usage of

  • Classes (Concept of Object Oriented Programming)
  • Multi Dimensional Arrays
  • Pointers
  • Functions

Guidelines:

 

  • Code should properly be indented and well commented.
  • Use only Dev-C++ for this assignment. If you are using any other tool then mention it at top of your code file as comments.
  • You are required to submit your solution files (.CPP and doc/docx) files as single zip file.  

 

Assignment Description

 

In this assignment, you are provided with a startup code attached with this assignment as “StartupCode.cpp”. Your job is to slightly modify this code as desired in this assignment.

First, you need to understand the working of the given code and execute it in Dev-C++. This is a mini Game, allowing three players to contest. Each Player will have to open three boxes from given one hundred boxes in 3 turns. There is a secret number in each box. In each turn, the secret number inside the selected box will add-up to the total score of player.  At the end, it will display the summary score of all players.

 

 

In this program, we have created a Player class which will keep record of individual player’s data i.e. name and score.  In main() function, we created three objects of Player class in the form of array. Doing this will allow three players to play the game.

A loop in main function is iterated to get name and score of three players. After getting player name and score, we are displaying result summary at the end of main function.

In this program, we have created five functions to perform all necessary tasks.

  • displayInformation() function is used to display the information about the game on top of output window.
  • fillBoard() function is taking a 2D array as argument and filling each element/box of array with random number from 1 to 100.  We are re-filling 2D array for each player. Element of this array are also referred as box.
  • displayBoard() function is also taking 2D array as argument and displaying box number from 1 to 100.

 

We are doing this for player to easily remember box number he/she want to open or already opened. It will show already opened box with character X indicating this box is already selected.

  • openBox() function is taking 2D array as argument. This function will get box number from player, add secret number stored at selected box into total score of player and set value of box to zero. Setting secret number of box to zero is allowing us to mark the box with X, so in next turn this box should not use again.    
  • sortPlayers() function is taking array of player and size of array as arguments. It is your task to write the code of this function.

 

Your Task

Your task is to slightly modify this code in order to show the Players result summary in sorted order as shown in the following snapshot (Highlighted in Red). You are required to write the implementation of sortPlayers() function to sort the players array in descending order on the base of player score.

Hint: The topic of bubble sort given in handouts will help you to perform your task easily.

You need to type in your own VU-ID (e.g. BC123456789) as one of the player’s name.

This will help us to verify that the code was written by you (not copied).

 

To understand the requirement clearly see the video file (sample_output.mp4) attached with this file. 

Sample working of the desired program is shown in attached video file “Sample_Output.mp4”.

 

Solution Guidelines

To get maximum marks you need to follow the guidelines given here.  

  • Completing implementation of sortPlayers() function to sort players array is the most important task in this assignment.
  • After completing required tasks, you are required to run the program and get screenshot of the sorted players score. To ensure originality, you are required to enter your VU-ID as one of the player’ name. Take screen shot of summary and paste it into MS word file.
  • Zip MS word and CPP file as single file and upload it. It is compulsory to send both CPP and Word files. If any of file will missing, you will lose a large portion of marks.

 

Hints:

For sorting of player array you need to understand the topic of bubble sort given in handouts.

If you understand the working of nested loops and accessing data member of class then you can easily sort the players array.  

Submission  

You are required to submit your solution files (.CPP and doc/docx) files as single zip file.

 

 

 

 

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 9261

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Attachments:

Replies to This Discussion

kuch samaj nhn a rhi...

mghay bhi bta dena samajh a janay pay

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

class Player {
private:
char name[20];
int score;

public:
bool operator >(Player const& rhs) {
return rhs.score >rhs.score;
}

Player(){
strcpy(name, "\0");
score = 0;
//cout"Constructor Called";
}
~Player(){
//cout"Destructor Called";
}
void setName(){
cin>>this->name;
}
char* getName(){
return this->name;
}
void setScore(int score){
this->score = score;
}
int getScore(){
return this->score;
}
};

void displayInformation () {
cout"This is a mini Game, allowing three players to contest.";
cout"Each Player will have to open three boxes from given one hundred boxes in 3 turns.";
cout"There is a secret number in each box. In each turn number, the secret number inside the selected box will add-up to the total score of player. At the end, it will display the summary of score of each player.\n\n";
}

void fillBoard(int array[10][10]){
srand(time(0));
for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
array[i][j] = rand()%100+1;
}
}
}
void displayBoard(int array[10][10]){
int *ptr = *array;

system("cls");

displayInformation();

for(int i = 1; i <= 100; i++){
if(*ptr != 0){
//couti"("*ptr")\t";
couti"\t";
}
else {
cout"X\t";
}
ptr++;

if(i%10 == 0)
coutendl;
}
coutendl;
ptr = NULL;
}
int openBox(int grid[10][10]){
int *ptr = *grid, choice = 0, secretNumber = 0;
cout"Enter the number of box to open it: ";
cin>>choice;

ptr = ptr+choice-1;
secretNumber = *ptr;
*ptr = 0;
return secretNumber;
}


void mySwap(Player &a, Player &b)
{

Player temp = a;
a = b;

b = temp;

}


void sortPlayers(Player players[], int size){


Player cmp_result;
for(int i = size - 1; i > 0; --i)

{

for(int j = 0; j < i; ++j)

{

if(players[j+1].getScore() > players[j].getScore() )

{

mySwap( players[j], players[j+1]);

}

}

}

// put your code here to sort the players in descending order on the bases of score
// Example Input
// Uzma 233
// Ali 280
// bc123456899 250

// Desired Output
// Ali 280
// bc123456899 250
// Uzma 233

}

main(){
int size = 3, board[10][10] = {0};
Player players[size];


displayInformation();

for(int x = 0; x < size; x++) {
fillBoard(board);
cout"Enter name of player "x+1" of "size": ";
players[x].setName();

for(int i = 1; i <= 3; i++){
displayBoard(board);
cout"Turn "i" of 3"endl;

if(i < 3) {
players[x].setScore(players[x].getScore()+openBox(board));
}
else{
char choice = '\0';
int offer = 25+rand()%51;
cout"Special offer take: "offerendlendl;

cout"You can take special offer or open last box."endl;
cout"To take special offer press y or Y and any other character to open your last box: ";
cin>>choice;

if(choice == 'y' || choice == 'Y'){
players[x].setScore(players[x].getScore()+offer);
}
else{
players[x].setScore(players[x].getScore()+openBox(board));
}
}
coutendlendl;
}
cout"Your Score: "players[x].getScore()endlendl;
}

sortPlayers(players, size);

cout"---------- Result Summary -------------- "endl;
for(int k = 0; k < size; k++) {
coutplayers[k].getName()"\t Score: "players[k].getScore()endl;
}
coutendl;
system("pause");
}

Attachments:

@ Zindgi

Miss I need your help in cs201 assignment #3 ....

Please do explain about this assignment ??????

and what is logic of this assignment ,,,, ?????/

also how can we code it ?????    

Uffffffffffffff i cant understand it !!




Simple function that take to argument first array and size of array and sort into  descending order and in this assignment we have to do same thing 

void sort(int arr[], int size)
{
int temp;

for(int i = 0; i < size; i++)
{
for(int j = 0;j < size - 1; j++)
{
if(arr[j] > arr[j+1])
{
//we need to swap
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}

@ will you pl Explain it more ..so that it will be easy to understand for me ,,at least !!

good job dear.....

thanks

yes 

correct 

if you are sorting in descending order then why you are swapping when arr[j] is greater than arr[j+1].

becose we require result in which arr[j] must be greater than arr[j+1]

think friend

samj a jati tu khud na kr late

@ Zindgi  

To phr ap ny Opr jo itni lambi kaweeta likhi hy wo kya hy ??

wo coding ni hy kya assignment ki ???    Koi Poem hy kya?

RSS

Latest Activity

Imran Khan replied to + M.Tariq Malik's discussion MTH601 Assignment No 01 Fall 2019 Solution & Discussion in the group MTH601 Operations Research
6 minutes ago
Profile IconImran Khan, Hashim and Aakash Ahmed joined + M.Tariq Malik's group
7 minutes ago
+ ! ! ! ! Mehαr Mαh꧂ replied to + M.Tariq Malik's discussion MGT201 Financial Management GDB Fall 2019 Solution & Discussion Last Date: 22-11-2019 in the group MGT201 Financial Management
8 minutes ago
+ ! ! ! ! Mehαr Mαh꧂ liked + M.Tariq Malik's discussion MGT201 Financial Management GDB Fall 2019 Solution & Discussion Last Date: 22-11-2019
8 minutes ago
+"Khwab Zaadi"+ liked + M.Tariq Malik's discussion MTH501 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 19-11-2019
15 minutes ago
+ "αяsαℓ " Ќąƶµяɨ •" replied to + M.Tariq Malik's discussion MGT201 Financial Management GDB Fall 2019 Solution & Discussion Last Date: 22-11-2019 in the group MGT201 Financial Management
26 minutes ago
+ "αяsαℓ " Ќąƶµяɨ •" replied to + M.Tariq Malik's discussion MGT201 Financial Management GDB Fall 2019 Solution & Discussion Last Date: 22-11-2019 in the group MGT201 Financial Management
27 minutes ago
+ "αяsαℓ " Ќąƶµяɨ •" replied to + M.Tariq Malik's discussion MGT201 Financial Management GDB Fall 2019 Solution & Discussion Last Date: 22-11-2019 in the group MGT201 Financial Management
27 minutes ago
Profile IconAmna Imran and Nisha Khan joined + M.Tariq Malik's group
39 minutes ago
+ ! ! ! ! Mehαr Mαh꧂ replied to +¢αяєℓєѕѕ gιяℓ's discussion Shadi Ho Rhi Hai Alhamdulillah.......... (^__^)!
41 minutes ago
UMER UMER posted a discussion
41 minutes ago
+ ! ! ! ! Mehαr Mαh꧂ replied to +***piya o ry piya***+'s discussion eng201
43 minutes ago
UMER UMER added a discussion to the group MGT101 Financial Accounting
47 minutes ago
Profile IconUMER UMER and Nisha Khan joined + M.Tariq Malik's group
49 minutes ago
Profile IconRizwan, Amna Imran, nudrat akram and 23 more joined Virtual University of Pakistan
49 minutes ago
UMER UMER liked + M.Tariq Malik's group MGT101 Financial Accounting
49 minutes ago
+ ! ! ! ! Mehαr Mαh꧂ liked + M.Tariq Malik's discussion ENG201 Business and Technical English Writing Assignment No 01 Fall 2019 Solution & Discussion
51 minutes ago
Amna Imran liked + M.Tariq Malik's group MGT603 Strategic Management
55 minutes ago
Amna Imran liked + M.Tariq Malik's group MGT603 Strategic Management
55 minutes ago
+ ! ! ! ! Mehαr Mαh꧂ replied to +***piya o ry piya***+'s discussion eng201
1 hour ago

Today Top Members 

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service