I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated. #include #include using namespace std; class QueenKnight { public: QueenKnight() { queens = 0; knight = 0; row = 8; column = 8; count = 0; for(int i= 0; i
Ramper
Posts
-
5Queens/5Knights on 8x8 board -
Splitting string into individual wordswish it was that easy, has to be a string with a leading space and multiple spaces between words.
-
Splitting string into individual wordsI need to Write a function that will, given an input string containing many words, split that string into individual words. For each word, the function should output the word, its starting index in the string, and its length to the console without using stream extraction operator. #include #include using namespace std; int main() { string sval = " The quick brown fox jumps over the lazy dog"; int cnt=1; int nsep = sval.find(" "); while (nsep > 0) { cout << "Word " << cnt << "=" << sval.substr(0,nsep) << endl; cnt = cnt + 1; sval = sval.substr(nsep+1); nsep = sval.find(" "); } cout << "Word " << cnt << "=" << sval << endl; #ifdef WIN32 system("pause"); #endif return(0); } Thats where i am so far, it will just split it into words but will not work if it begins with a space or if there is more than 1 space between words. I believe i need s.find_first_not_of but not sure how to incorprate it or if thats even my problem any help?
-
inputing string & int from file to array.File i have the code for is like: 34 34 45 32 .... File i need to be able to get grades from is: Name 35 54 34 44 34 54 34 54 34 54 Name 34 34 ... Need help on how to somehow get the name strings into an array somehow. As i have it now it is just inputFile >> data[students][tests] which is a declared 2d array with 15 students and 10 tests.
-
inputing string & int from file to array.Have a name followed by 10 int's and it repeats for 15 names. Have a program that will input just the int into a 2d array if no string is involved. Need to somehow input the names from the file (every 11 lines) into a seperate array. Any suggestions?
-
Inputing data from .txt to array.there is no problem with the code that i posted. The problem i am facint is that the posted code will only read a list of integers without a student name. The .txt i need to read from is supposed to have the student name then 10 grades after then another name and another 10 grades. Don't know how to retrieve the name. Thanks
-
Inputing data from .txt to array.I have a program that is able to take the numbers out of the .txt if it is just a list of numbers. Problem is, I have a file with Names before the grades. I believe i need to set up another array inside the first one to fill with names. The .txt file will look like: Name grade grade grade grade grade grade grade grade grade grade Name ... Have 15 Names with 10 grades under each. I guess what i'm trying to do is take the strings out of the file. Is there a way to take the strings(there is a string every 11 lines) Here is what i have now: #include #include #include #include #include #include using namespace std; const int TESTS = 10; const int STUDENTS = 15; void displayGrades( int [][TESTS] ); void getGrades( int [][TESTS]); int main() { int data[STUDENTS][TESTS] = {0}; getGrades( data ); cout <> data[student][test]; } } } void displayGrades( int data[][TESTS] ) { double testTotal = 0.0; double classTotal = 0.0; double squared = 0.0; double var = 0.0; double sdev = 0.0; int mxm = data[0][0]; int min = data[0][0]; cout << "\nGrade summary" << endl; cout << "--------------" << endl; cout << left << setw(7) << "Student" << right << setw(5) << right << "Ex1" << setw(7) << "Ex2" <
-
Inputing data from .txt to array.I have a program that is able to take the numbers out of the .txt if it is just a list of numbers. Problem is, I have a file with Names before the grades. I believe i need to set up another array inside the first one to fill with names. The .txt file will look like: Name grade grade grade grade grade grade grade grade grade grade Name ... Have 15 Names with 10 grades under each. I guess what i'm trying to do is take the strings out of the file. Is there a way to take the strings(there is a string every 11 lines) Here is what i have now: #include #include #include #include #include #include using namespace std; const int TESTS = 10; const int STUDENTS = 15; void displayGrades( int [][TESTS] ); void getGrades( int [][TESTS]); int main() { int data[STUDENTS][TESTS] = {0}; getGrades( data ); cout <> data[student][test]; } } } void displayGrades( int data[][TESTS] ) { double testTotal = 0.0; double classTotal = 0.0; double squared = 0.0; double var = 0.0; double sdev = 0.0; int mxm = data[0][0]; int min = data[0][0]; cout << "\nGrade summary" << endl; cout << "--------------" << endl; cout << left << setw(7) << "Student" << right << setw(5) << right << "Ex1" << setw(7) << "Ex2" <