Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Trying out what I have learned in C++

Status
Not open for further replies.

q-bertsuit

Junior Member level 3
Joined
Nov 29, 2011
Messages
29
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,559
Hi guys,

I've been reading tutorials about C++ the last few days and been trying some of the stuff out. Now I thought I would try to write some bigger code and test out what I have learned. I have a little trouble deciding what approach to take.

I thought I'd try solving the Knight's tour Knight's tour - Wikipedia, the free encyclopedia.

My first thought is to use a linked list with 64 structures, were each part of the list contains an Xpos, Ypos and number of moves it has done from that particular position. The point is not to get the fastest solution, but to get it to work at all.

Is there any point using classes in this program? I'm pretty sure I could get it working if I spend enough time, but I would also like to do it properly to test what I have learned the last few days and to get in to good programming habits.
Thank you
 

Is there any point using classes in this program? I'm pretty sure I could get it working if I spend enough time, but I would also like to do it properly to test what I have learned the last few days and to get in to good programming habits.

The major reason to code in C++ versus C is the utilization of object model. Of which Classes are an integral part inheritance, polymorphism, and encapsulation.

Besides coding without Classes in C++ is basically coding in C.

C++ is not the best solution for all applications, however if you wish to employ Object Oriented techniques it is a viable option.

BigDog
 
Thank you for your reply.

That is precisely why I would like to include some classes in my program, so it wouldn't just be plain old C, but I'm still having some difficulties seeing what my classes would do. Maybe have objects that contain the positions and moves done from a particular square, and a class that creates and updates these objects? The point is to get a feeling for when to us OOP and to get the syntax in to my fingers.

Thanks again
 

I'm not familiar with the "Knight's Tour."

However, to develop an object requires breaking down the system into in most rudimentary parts.

Suppose you were modelling a Chess game, you would first form an elementary (base) class, the ChessPiece, which has attributes of position. Then you would create new Classes for each Chess piece by inheriting the ChessPiece Class and adding new attributes and methods specific to the particular piece. For instance the Pawn can move either one or two positions only in the forward direction, therefore you would add a method for this movement including the above limitations. You would also need a method which described the "Taking of another Chess piece", etc.

BigDog
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top