hi, i need help converting this java program to C++...are there any
programs or nething that could be used to do this faster??
class hw2 {
static public void main (String args[]) {
hw2.test();}
Board board = new Board(8);
if ( board.fillInRem ainingLevels() )
board.print();
else
System.out.prin tln("Couldn't find solution");
}
static void test () {
Board board = new Board(8);
// board.addQueen( int, int) calls: new Queen(int, int)
if ( ! board.addQueen( 5,6) )
throw new Error("failed test1");
if ( board.addQueen( 6,7) )
throw new Error("failed test2");
if ( board.addQueen( 4,7) )
throw new Error("failed test3");
if ( board.addQueen( 4,5) )
throw new Error("failed test4");
if ( board.addQueen( 5,5) )
throw new Error("failed test5");
}
}
class Board {
int size;
Queen [][] square;
int currentLevel = 0;
boolean done = false;
Board(int size) {
this.size = size;
this.square = new Queen[size][size];
}
boolean addQueen(Queen queen) {
if (queen.canCaptu re(this))
return false;
else {
this.square[queen.xPos][queen.yPos] = queen;
return true;
}
}
boolean addQueen(int x, int y) {
Queen queen = new Queen(x, y);
return this.addQueen( queen );
}
void removeQueen(Que en queen) {
this.square[queen.xPos][queen.yPos] = null;
}
boolean fillInRemaining Levels() {
if (this.currentLe vel >= this.size) {
this.done = true;
return true;
}
int level = currentLevel;
for (int x = 0; x < this.size; x++) {
Queen queen = new Queen(x, this.currentLev el);
if (this.addQueen( queen )) {
this.currentLev el++;
this.fillInRema iningLevels();
// When we study exceptions, there will be a better
// way to handle this.
if (this.done)
return true;
// remove queen and restore currentLevel if backing up
this.removeQuee n( queen );
this.currentLev el = level;
}
}
return false;
}
void print() {
for (int x = 0; x < this.size; x++) {
for (int y = 0; y < this.size; y++) {
if (this.square[x][y] == null)
System.out.prin t(" .");
else
System.out.prin t(" Q");
}
System.out.prin tln();
}
System.out.prin tln();
}
}
class Queen {
int xPos;
int yPos;
Queen(int x, int y) {
this.xPos = x;
this.yPos = y;
}
boolean canCapture(Boar d board) {
for (int i = 0; i < board.size; i++) {
if ( board.square[i][this.yPos] != null )
return true;
if ( board.square[this.xPos][i] != null )
return true;
}
for (int y = 0; y < board.size; y++) {
int delta = this.yPos - y;
int x1 = this.xPos + delta;
int x2 = this.xPos - delta;
if ( x1 >= 0 && x1 < board.size && board.square[x1][y] != null )
return true;
if ( x2 >= 0 && x2 < board.size && board.square[x2][y] != null )
return true;
}
return false;
}
}
thank you 4 1763
"jipster" <wi*******@aol. com> wrote... hi, i need help converting this java program to C++...are there any programs or nething that could be used to do this faster??
Text editors with syntax highlighting, maybe?
[..]
How much are you prepared to pay for this job?
:) how much are we asking
jipster wrote: hi, i need help converting this java program to C++...are there any programs or nething that could be used to do this faster??
I don't think your C++ teacher will be much impressed if you
hand in a C++ version of this poor Java '8-queens' solution.
--
Karl Heinz Buchegger kb******@gascad .at
"jipster" <wi*******@aol. com> wrote in message
news:34******** *************** *******@localho st.talkaboutpro gramming.com... hi, i need help converting this java program to C++...are there any programs or nething that could be used to do this faster??
("nething"? You're entering the world of programming now. You might want
to use actual words. Compilers are going to be a lot pickier than your IM
buddies.)
You could search Google for something which would help translate that code.
Or, you could search Google for an actual C++ version of the 8 Queens
problem. Or, if this is for a class, you could try writing the program
yourself(!), and asking here for help with specific problems you have
getting it to work correctly (once you've actually written some C++ code,
that is).
-Howard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rex_chaos |
last post by:
Hi all,
I have a question about datatype converting. Consider the following
types
std::complex<double>
and
struct MyComplex
{
double re, im;
}
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With numarray, help gives unhelpful responses:
|
by: alyssa |
last post by:
Hi guys,
May i know how to declare a string of binary data and pass it to the method?
For example, int a={10010001120420052314}
is it correct?
and if i have receive the binary data, may i know how to separate them and
store each of them inside a variable such as int cust_id?is it possible? For
example, the first four bits is the customer id, the second four bits is the
call id and third 8 bits is the date and the remaining is the time..
...
|
by: Clark Stevens |
last post by:
I have a program that I'm converting from VB6 to VB.NET. It reads in a text
file containing barcode numbers and their corresponding descriptions. Then
the user enters the barcode number and the program finds the matching
barcode description.
In VB6 I used an UDT to store the barcode number along with the description.
Then I declared an array of the barcode UDT.
I'm thinking of converting the UDT to a structure in VB.NET and doing...
|
by: robert d via AccessMonster.com |
last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections
are of the following structure:
Dim wsName As DAO.Workspace
Dim dbName As DAO.Database
Dim rsName As DAO.Recordset
Set wsName = DBEngine.Workspaces(0)
Set dbName = wsName.OpenDatabase(CurrentProject.FullName)
Set rsName = dbName.OpenRecordset("SQL Statement")
| |
by: Paraic Gallagher |
last post by:
Hi,
This is my first post to the list, I hope somebody can help me with this
problem. Apologies if it has been posted before but I have been internet
searching to no avail.
What I am trying to do is provide a simple method for a user to change a
config file, for a test suite.
The config file consists of a number of keys, eg. build number, target
device, etc.
|
by: manmit.walia |
last post by:
Hello All,
I have tried multiple online tools to convert an VB6 (bas) file to
VB.NET file and no luck. I was hoping that someone could help me covert
this. I am new to the .NET world and still learning all help would be
greatly apperciated.
Attribute VB_Name = "Module1"
Option Explicit
|
by: anukagni |
last post by:
Hi,
iam having an database for that i have created an user manual includes help topics ..I prepared in the word format and i want to covert this to html help .
Iam having Ms Html workshop but i found to hard to create any body sugess me to create an html help by converting the word matters too....
needed solution ... thanks in advance..
thanks,
anukagni
|
by: minterman |
last post by:
1. the program needs to convert btu to jules
2. Convert calories to joules
3. Convert joules to joules
4 exit the program.
if the user type anything other than 1-4 the program should print a error message.
here is my code.
import java.util.Scanner;
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |