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 !
#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;
}
//----------------------------------------------------
c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc.. Please...
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 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: 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 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 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 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 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 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 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 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...