Question

c++ can use if else, loop,function ,array,file i.o.

Can not use swtich, global variables etc..  

Please do all parts. previously I post 3 time for part1 ,2 and 3 but I can't make it into one complete program code. I even try to post a questions ask and post the 3 parts of code for experts to put it together. But experts said it's not enough information. please help... Thank you !

Program Objectives: Allow students to create arrays Allow students to get experience with declaring and initializing arrays A

Phase 6 Part 2: Generating the list of items for the players You are going to create a string array with a size of 16 to hold

A random item is going to be selected from the item collection array This item will be placed in the player item array The pr

How the Assignment will be Graded: Part 1 (20 points) Part 2 (40 points) Part 3 (40 points) Implementing the Attack Function

Program Objectives: Allow students to create arrays Allow students to get experience with declaring and initializing arrays Allow students to get experience with passing arrays Allow students to get experience with printing out all of the elements in an array Program Description: This program is going to include Arrays. We will implement items in the game using arrays. Arrays will also be used to check of a character exist or not within the roster Phase 6 Part 1: Using Arrays to check if a character exist You will create a new function named CheckCharacterExist2 - This function will be the exact same as the CheckCharacterExist with a few small tweaks - This function is going to passed in two arguments: the roster file object and the name of the character that the user wishes to load The function is going to determine if the character exist by doing the following Look in to the roster text file and store all of the names to an array Then it is going to take the name the user entered and check to see if that name is in the array If the name is in the array the character exist and the function will return true If the name is not in the array the character does not exist and the function will return false Make sure you are storing all of the file contents in an array and looking inside the array to see if the character exist or not.
Phase 6 Part 2: Generating the list of items for the players You are going to create a string array with a size of 16 to hold the total number of items in the game. The array will be initialized with the following values - Big Potion - Med Potion - Small Potion Net Spear Dagger Rock Gloves Brass Knuckles Iron Fist - Helmet - Leggings Chest Plate - String Feather Sandal - Please make sure that the items in your program matches the items in this list. Make sure they are spelled exactly the same as this list You will also create an empty string array with a size of 6 for both player 1 and player 2 You will have to create a function GeneratePlayerltems - This function is going to take in five arguments Item collection array Player 1 item array Player 2 item array Item collection size Player item size Player special item - This function is going to fill the empty player item array with items from the item collection array
A random item is going to be selected from the item collection array This item will be placed in the player item array The program must prevent duplicate items from being put into the array So if the same random item is selected twice it will not appear twice in the player item array. The first array element for player items will be the player special item that is determine base on the faction Ex: playerltem[0] "Sword" ("Armor", "Coincidence") After the function is called the player item array should be completely filled out - The first element of the array should be the special item that is associated with the player Phase 6 Part 3: Using the items during the duel During the duel, whenever the user wishes to use an item The program is going to print all the items that is contained in the array to the screen - The user is then going to have the option to select the item he wishes to use If the item is not in the array then the player will lose a turn Nothing will happen and it will be the next player turn You will have to create another function named PlayerUseltems The details of this function will be provided in a separate document The item that was selected from the item list will have to be set to empty So that way the user will not be able to use the same item over and over again
How the Assignment will be Graded: Part 1 (20 points) Part 2 (40 points) Part 3 (40 points) Implementing the Attack Function Correctly (40 points) *The program must compile and be able to run. If it does not compile and run at the start then 50 points will be taken off *The program must contain comments *Program must meet the requirements. Additional points will be taken off if the requirements are not fully met
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>
using namespace std;
//------------------------------
bool CheckCharacterExist(ifstream file,string character){
string name[100];
string str;
int i=0;
while(getline(file, str)){
name[i]=str;
i++;
}
for(int k=0;k<i;k++){
if(name[k]==character)
return true;
}
return false;

}
//-------------------
int isPresent(string A[],string str,int n){
for(int i=0;i<n;i++){
if(A[i]==str)
return i;
}
return -1;
}
//---------------------------
void GeneratePlayerItems(string item[],string player1[],string player2[],int item_collection_size,int player_item_size){


for(int i=0;i<player_item_size;i++){
while(1){
srand(time(0));
int r=rand()%item_collection_size;
if(isPresent(player1,item[r],player_item_size)==-1){
player1[i]=item[r];
break;
}
}
}

//----------------------
for(int i=0;i<player_item_size;i++){
while(1){
srand(time(0));
int r=rand()%item_collection_size;
if(isPresent(player2,item[r],player_item_size)==-1){
player2[i]=item[r];
break;
}
}
}

}
//--------------------
void playerUseItems(string item1[],string player1[],string player2[],int s){
string item2[s];

for(int i=0;i<s;i++){
item2[i]=item1[i];
}
int p1=0,p2=0;
string str;
int turn=1;

int total_try1=0;
int total_try2=0;

while(1){
if(turn==1){
cout<<endl<<endl;
for(int i=0;i<s;i++){
cout<<item1[i]<<", ";
}

cout<<"\nGuess an item that may be in list of item of PLAYER1: ";
getline(cin, str);
total_try1++;
int k=isPresent(item1,str,16);
if(isPresent(player1,str,6)!=-1 && k!=-1){
p1++;
cout<<"Player1 score:"<<p1<<endl;
item1[k]=" ";
}
else{
turn=2;
if(k!=-1)
item1[k]=" ";
}
}
else if(turn==2){
cout<<endl<<endl;
for(int i=0;i<s;i++){
cout<<item2[i]<<", ";
}

cout<<"\nGuess an item that may be in list of item of PLAYER2: ";
getline (cin, str);

total_try2++;
int k=isPresent(item2,str,16);
if(isPresent(player2,str,6)!=-1 && k!=-1){
p2++;
cout<<"Player2 score: "<<p2<<endl;
item2[k]=" ";
}
else{
turn=1;
if(k!=-1)
item2[k]=" ";
}
}
if(total_try1>=20){
turn=2;
}
if(total_try2>=20){
turn=1;
}
if(p1==6){
cout<<"Player 1 wins!"<<endl;
break;
}
else if(p2==6){
cout<<"Player 2 wins!"<<endl;
break;
}
else if(total_try1>=20 && total_try2>=20){
cout<<"Nobody wins!"<<endl;
break;
}

}
}
//----------------------------
int main(){
ifstream file;
file.open("character.txt");
   if(!file)
   {
       cout << endl << "Failed to open file ";
       return 1;
   }
   string item[16]={"Big Potion","Med Potion","Small Potion","Net","Spear","Dagger","Rock","Gloves","Brass Knuckles","Iron fist","Helmet","Leggings","Chest Plate","String","Feather","Sandal"};
string player1_item[6];
string player2_item[6];

GeneratePlayerItems(item,player1_item,player2_item,16,6);

playerUseItems(item,player1_item,player2_item,16);

return 0;
}
//----------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • This program will store a roster of most popular videos with kittens. The roster can include...

    This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • java Part 1 Create a NetBeans project that asks for a file name. The file should...

    java Part 1 Create a NetBeans project that asks for a file name. The file should contain an unknown quantity of double numeric values with each number on its own line. There should be no empty lines. Open the file and read the numbers. Print the sum, average, and the count of the numbers. Be sure to label the outputs very clearly. Read the file values as Strings and use Double.parseDouble() to convert them. Part 2 Create a NetBeans project...

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

  • Question: File response. You must create a program called “Assigment_Mod9.cpp” that allow to manage the inventory...

    Question: File response. You must create a program called “Assigment_Mod9.cpp” that allow to manage the inventory of a store. The program must have a menu that allow to perform the following three actions: Add a new item Remove an item Replicate n times and existing item The program must have two dynamic arrays: one for store the name of the product and other to store the price of the product. The size of each array must be of the same...

  • Write a C program as follows: Single source code file Calls a function with an arbitrary...

    Write a C program as follows: Single source code file Calls a function with an arbitrary name (i.e. you name it) that accepts two arrays of the same size The function should add each element in the arrays together and place the values in a third array Each array element, each array address, and the sum are printed to the screen in tabulated format with headersI also would like to request that LOTS of comments be included, as I need...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • USE C++ TO DEVELOP THE CODE. THANKS IN ADVANCE create an array of strings with a...

    USE C++ TO DEVELOP THE CODE. THANKS IN ADVANCE create an array of strings with a size of 10. explain the story to the player, whatever story you wish to tell. the player starts with 3 items. over the course of several adventures, 1. the player gains 3 items and has to name each of them. for example: BunnySword or FlameGuitar - because of cin limitations, the name can only be one word. 2. the player uses 1 item, making...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT