Home » C++ Programming


I have an exercise that has the following structure:

You given a folder. In a folder (and subfolders) there are a lot of
textures of different sizes and format (png, jpg). Your task is to
write a standalone application, which may pack them to the set of
square textures (each texture has to have power of 2 dimensions, i.e.
256x256, 512x512. 512x512 is optimal). Should be look like this:

I have no idea where to start from.

So anyone can give me some idea how to start?

I have read some articles about bin packing like

"Algorithms for  Two-Dimensional Bin Packing and Assignment Problems" by  Andrea Lodi

but I don't know how to implement it in c++.

I am not looking for a source code. I just need some guidance.

Thank you.



4 Answers Found


Answer 1

If you can use MFC you could use CBitmap and CImage to do a lot of this work (using GDI+).  If you are using C++/CLI with .NET you could use an .NET Image object to get a lot of the functionality as well.



Answer 2

Really this isn't that hard. The theory is to put them into one image and then use a function like GDI BitBlt or GDI+ Bitmap::Clone to copy out only what you need.

The important part is to realise that they don't need to copy the entire image at once, you can select parts of it. So if your image is a 10x10 image and in the source it is at coordinates (20, 10), then the call to BitBlt would probably be something like

BitBlt(hDst, 0, 0, 10, 10, hSrc, 20, 10, SRCCOPY);

assuming you are copying it to a location for the image on its own.

To make this work though you need to keep an index or keep the images at a regular size. So just a regular table (array of structures, maybe using vector) will be enough to store it. This table can just simply store the relevant information for the image.

Well, just read the GDI+ or GDI documentation. You should prefer GDI+ over GDI because of complexity. Once you know the library it should be pretty easy to figure out what to do.


Answer 3

Thank you for your answer.

I study now GDIi+ and I hope that I find what I need.

But trying to apply what I've seen there I have a problem.

I try to draw a line and I receive the following error:

Cannot open include file: 'stdafx.h': No such file or directory

And I don't know how to handle with it.


Answer 4

I was looking at the GDI+ classes and I don't think that I find there what I need.

As I thought it I need a container or a vector that has a dynamic dimension where to store the images and the an algorithm that is gonna arrange them

in order that no space be wasted.

I just cannot figure it out how to do this with the Bitmap::Clone method. 

Search for  exercise


I have an exercise that has the following structure:

You given a folder. In a folder (and subfolders) there are a lot of
textures of different sizes and format (png, jpg). Your task is to
write a standalone application, which may pack them to the set of
square textures (each texture has to have power of 2 dimensions, i.e.
256x256, 512x512. 512x512 is optimal). Should be look like this:

I have no idea where to start from.

So anyone can give me some idea how to start?

I have read some articles about bin packing like

"Algorithms for  Two-Dimensional Bin Packing and Assignment Problems" by  Andrea Lodi

but I don't know how to implement it in c++.

I am not looking for a source code. I just need some guidance.

Thank you.



I have a problem with an exercise.

Until here it works just fine



: System::Void btnrezultat_Click(System::Object^ sender, System::EventArgs^ e) {




double x, y;


double i;




do {


if(x<=0 || y<=0 || x>y)

lblRzultat->Text= String::Format(

"Trebuie ca 0 < X <= Y");


I work in visual c++ form application.

When I put the rest of the code:


while (x<=0 || y<=0 || x>y);


for (i = x; i<y; i++)


switch(tip_numar(i)) {



lblRzultat->Text= String::Format(

"Este deficient", i.ToString());



lblRzultat->Text= String::Format(

"Este perfect ", i.ToString());



lblRzultat->Text= String::Format(

"Este abundent ", i.ToString());


It blocks while executing.

And here are the definitions:



suma_divizori(int n) {


int i, s=1;


for(i=2; i<= n/2; i++)


if (n%i == 0) s+=i;


return s;



// function that returns the type of the number(DEFICIENT , PERFECT , ABUNDENT)


int tip_numar( int n) {


double s = suma_divizori(n);


if(s<n) return DEFICIENT;


if(s>n) return ABUNDENT;


return PERFECT;


Thank you



The exercise says:

(Employee Class) Create a class called Employee that includes three pieces of information as data members--a first name (type string), a last name (type string) and a monthly salary (type int). Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10 percent raise and display each Employee's yearly salary again.

I need to know if I am heading in the right direction so here is what I have so far:

// ex3.14.cpp : Defines the entry point for the console application.




using std::cout;

using std::cin;

using std::endl;


using std::string;

using std::getline;

// Employee class definition

class Employee



Employee( string ); // constructor that initializes an Employee object

void setFirstName( string ); // function that sets the first name

string getFirstName(); // function that gets the first name

void displayMessage(); // function that displays a message

void setLastName( string ); // function that sets the last name

string getLastName( string ); // function that gets the last name

void displayMessage(); // function that displays a message

int salary;



as an exercise to understand dispatchers, I'm trying to rewrite a working program from this example : http://msdn.microsoft.com/en-us/library/ms741870.aspx. The problem is, I always get a Error1The type or namespace name 'Dispatcher' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?) when I try to compile. 

Here's the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace TestDelegate
  publicpartialclass Form1 : Form
    privatedelegatevoid NoArgDelegate();
    privatedelegatevoid OneArgDelegate(String arg);

    public Form1()

    privatevoid button1_Click(object sender, EventArgs e)
      // Change the status image and start the rotation animation.
      button1.Enabled = false;
      button1.Text = "Contacting Server";

      // Start fetching the weather forecast asynchronously.
      NoArgDelegate fetcher = new NoArgDelegate(
      fetcher.BeginInvoke(null, null);

    privatevoid FetchWeatherFromServer()

      // Schedule the update function in the UI thread.
        new OneArgDelegate(UpdateUserInterface), 

    privatevoid UpdateUserInterface(String weather)
      //Update UI text
      button1.Enabled = true;
      button1.Text = "Fetch Forecast"; 

Looking a little deeper, i couldn't find where the dispatcher method is "placed". So, the question is: how can i make this program to run?

I'm using VS2010 with .NET framework 4


i am still noob at programming..

my lecturer gave me a lesson to make a simulation.....

i pretend to do drawing a simple building and the top of the building someone drop a ball so it look like bumping or bouncing.

but we must print out the value of bumping ball..

the simple drawing i need like this : http://www.ziddu.com/download/12269762/untitled.bmp.html thank u before,it is possible to

do this in VB.net , if it can't, may u suggest how to make it more easily to implement it into VB.net..


Tq u...regret..:)..

The tips and strategies in the following pages are the most effective techniques that will help you realise your height increasing goals. There are hundreds of different ways to grow taller. You will learn which ones are the easiest, fastest and most effective. Preparation Notes The exercises included in this book will stimulate overall growth and height gain, function to structurally lengthen the spinal column, improve posture, and straighten any excessive curvature of the spine. By performing the exercises, you will also benefit from greater health, stronger back and abdominal muscles, increased flexibility, and the alleviation and prevention of lower back pain. These exercises are illustrated, with simple and easy to understand instructions. These exercises are safe, effective, and easy to do by people of all ages and fitness levels. The exercises require no special equipment or apparatus and can be done in the privacy of your own home. Here are a few things to bear in mind before exercising: 1.Wear loose clothing that does not restrict movement. 2.Stretching exercises should be performed bare-footed. 3.Empty your bladder and bowel before you begin. 4.Warm up before exercising. 5.Perform the stretching exercises slowly and smoothly in a controlled manner. This applies to going into a position and coming out of it. 6.Stretch to a point and hold for 30-seconds. Do not worry if you cannot hold for 30 seconds when you have just begun. As your muscles become more flexible, you will gradually be able to hold for longer periods. 7.Do not strain yourself beyond the point where you feel pain. If any exercise causes your legs to tingle, feel numb, or weak, discontinue the exercise. 8.Relax while stretching. Only a relaxed muscle will allow itself to be stretched. 9.Breathe naturally and smoothly. 10.Be patient and persistent. Do not rush or force yourself in any way.

I have this problem:

Problem B - Ash Cloud

It's chaos at airports!A volcano just erupt causing an ash cloud that spreads and prevents air circulation.Onilândia's government is very concerned and want to know when the ash cloud will reach the airports onilandeses.

The map is a rectangle that is divided into smaller squares.Given the situation under review, are distinguished only three types of squares: cloud (indicating that this sector of the map is now covered by a cloud of ash), airport (letter 'A', indicating that this sector of the map contains a airport) and all the others (who have now not a cloud or an airport).An example of a map would be shown in the following figure:

 As time passes the situation worsens.   In fact, for each day that passes, the cloud expands into a grid horizontally and vertically.Put another way, after one day, all grid cells that were adjacent (vertically or horizontally) to a square cloud, they are also to contain clouds.Exemplifying the situation after two days, we would have the following:


  Tomorrow (1 day later)
  2 days after

To properly prepare contingency plans, the government needs to know two things: how many days it will take until at least one airport to get covered by the cloud and hence how many days the airports are all covered by cloud.You need help!

The Problem

Given a graph of L rows by C columns indicating the current position of the cloud and the airport, your task is to find N <sub>min,</sub> the number of days until the first airport to stay under the cloud of ash and N <sub>max,</sub> the number of days until all airports remain covered by ashes.


In the first line of input is two integers L and C, separated by a space, indicating the number of rows and number of columns of the map.

Following are exactly L lines each containing exactly C characters, describing the map.Each of the characters can be:

'#' ,Indicating that the grid currently has a cloud'A' , indicating that the grid has an airport'.' , Indicating that the grid is not currently a cloud or an airport

  There is always at least a square grid with a cloud and an airport, but you should not assume anything about the game the other squares.


The output should consist of exactly one line containing two integers N and N <sub>min max,</sub> separated by a single space, indicating the number of days until a first airport is covered by the cloud and the number of days until all airports remain covered.


  Are guaranteed the following limits in all test cases that will be placed on the program:

1 ≤ L,C ≤ 1 000
 Dimensions of the map
Note on assessment

 For a set of test cases worth 50% of the points, the number of rows and columns is less than 50.

Sample Input
7 8..#...##.##.....###.A..A.#.......#....A....A............
Example Output
2 4

I have made the folowing code:
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char mapa[1000][1000];
char tempmap[1000][1000];
int L;
int C;
int Nmin=0;
int Nmax=0;
char ltemp[1000];
int aeroportos=0;
int aeroportost=0;
int dias=1;
bool nfeito=true;

//gets and paints the map
cin >> L;
cin >> C;

for (int x=0; x<L;x++) {
cin >> ltemp;
for (int y=0;y<C;y++) {
if (mapa[x][y]=='A') {

//make the calculations per day
cout << "ola";
while(nfeito) {
for (int x=0; x<L;x++) {
for (int y=0;y<C;y++) {
for (int y=0;y<C;y++) {
if(mapa[x][y]=='#') {
if(x>0) {
if(y>0) {
if(x<(L-1)) {
if(x<(L-1)) {
if (Nmin==0) {
if (aeroportos>aeroportost) {
if (aeroportost==0) {
cout << Nmin << " " << Nmax;
return 0;

But it always ends in a infinite loop.
Where is my mistake?



On Lab 1, exercise 2, step C, while trying to set the STS metadata location to https://ip-sts-01.federatedidentity.net/federationmetadata/2007-06/federationmetadata.xml , the remote server returned an error: (504) Gateway time out. May i know is this the correct location?


How do you make the tab key invoke command such as in Exercise 40 ,Page 51?

I am getting the '404 not found' error in the WP7 lab exercise on Push Notification (the final version). See the screenshot.

When I send a Tile Notification, first nothing happens. Neither the emulator receives it anything nor any error is raised. But when I send it again this error occurs.

The steps followed are as follows:

1. Started both the PushNotification and Weather projects simultaneously as directed.

2. After 30 seconds it is stopped and restarted. Ensured that the connection is established now and the 'Active Clients: 1' is shown in 'Weather'.

3. Then sent an http notification and verifed that it is received in the emulator correctly.

4. Then using the 'Back' button exited the app in the emulator and pinned the app to the Start page.

5. Now sent a Tile Notification. It appers in the 'sent log' in Weather window. But nothing is received in the emulator. No error is raised.

6. So, sent a Tile again. Now it results in this error.

I have verified my code with that provided with the lab. Earlier it was noted that the lab docs were not updated but found the code to be running correctly. Here both the doc and code are verifed. This error is coming with both mine and lab's code. What am I missing?

-- ThanQ...



This has a reference to the Hands-On Lab exercises that were installed along with WP7 Dev Kit. I have the following issues with the lab on "Windows Phone Navigation and Controls".

1. ListBox Binding: In Ex2, Task 2, Step 10, the code "lstPictures.ItemsSource = photos;" is raising an error "Items collection must be emptied before using ItemsSource". I have compared the 'End' code with what I have typed and found to be exactly the same. What is wrong here? Or what am I missing?

2. Folder not showing up in Intellisence: In Ex1, Task 1, Step 16, a folder "Misc" is created. When I am typeing the code "using ...Misc;" in Ex2, Task 2, Step 6, intellisense was not showing up "Misc" folder. It was showing only "Views" in which some xaml files were created. I had to drop this folder, recreate it and create the two .cs files in this project and copy the code to them before all these were recognized by VS. In Ex1, after copying the two .cs files, I had compiled and executed the code several times. In earlier exercises, adding assets / resources from the lab's 'Source' directory didn't post any problem. What could be wrong here?

-- ThanQ...




This has reference to the hand-on lab, "Windows Phone Navigation and Controls". I have the following issues:

1. A static resource style not found: In Ex2, Task 3, Step 5, style of txtUrl was set to {StaticResource PhoneTextBoxStyle}. But no reference to thie 'PhoneTextBoxStyle' is found. Hence I am not able to run this option.

2. The picture just below this step, in Step 6, show the phone in landscape. No step in Task 3, before Step 6, was asking to set "Orientation" to landscape.

-- ThanQ...



I am trying to complete chapter9 but stuck in Exercise 4 - Install AD DS and Create a New Domain Tree, hope to get help!

I have 3 servers: SERVER10, SERVER20, SERVER30




I have configured standalone SERVER10 as below:

Primary DNS Server (Exercise1)

installed AD DS and create a New Forest (Exercise2).

Created a Manual Zone Delegation (Exercise 3)

I am able to ping to SERVER10 from SERVER20 and vice versa.

But stuck on step 14:On the Name the New Domain Tree Root page, type northwindtraders.com and click Next.

When i click next i encouter an error: An Active Directory Domain controller for the domain northwindtraders.com could not be contacted. Ensure the DNS domain name is typed correctly.

I am not able to move to next step after that. Can anyone help!!!!





First problem is on page 768 step 13. I can't get that result. I mean those location errors are still there.

Is there anyone can make this work? I need to know if it is my mistake or if I should not follow the steps.

Thank you.




I'm getting the following error on step 9:  "Error:  Executing the query "delete from stg_Customer where FileName = ?" failed with the following error:  "invalid object name 'stg_Customer'.

Has anyone seen this error before?




The note on Page 49 of the (Word) document addresses the situation where the SQL Express is not being used (my situation) and states:

<add name="LocalSqlServer" connectionString="data source=.\<YOURINSTANCESQLEXPRESSNAME>;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>

What should this connection string be like in the case of local instance of SQL Server 2008 and the path to the aspnetdb.mdf being c:\work\sample?

Is the proposed syntax |DataDirectory|aspnetdb.mdf correct?
I have a question about the sample “Exercise 1: Using Worker Role External Endpoints”.
This hands on lab is a howto create a net.tcp wcf service in azure.
What is the reason for this sample? In my opinion, there are web roles, which are intended to provide wcf web services(over http(s)).
There are several problems with this sample. One is mentioned in the documentation: It is not possible to scale out(to use more than one wcf service).
The second problem I see is the following: What happens if azure decides to shut down the current instance, and to create a new one? There Is no “BeforeShutdown” event, and it seems impossible to keep any states or whatever for the new worker role.

Besides those concerns, there might be others I do not know yet. 
Even on the Microsoft architecture website (http://msdn.microsoft.com/en-us/library/dd179341.aspx) the worker role is mentioned as background/asynchronous process for web roles, and not as host for wcf services. And only because it can be used for hosting does not mean it has to.

Here now my question:
I want to write a chat service for azure. Should this service be a web or a worker role?
And what is the use of this sample?


Hi all, I'm currently teaching myself Visual Studio 2010, have purchased the course books (and the course, but they can't get enough people to run it locally so I'm doing it this way for now)

Seeing that I always do things the hard way, I've purchased VS 2010 Professional and doing the VS 2008 course.....

Anyway I have a simple question that been bugging me.

the course says :

Task 4: Create an event procedure for the Page_LoadComplete Event.

The answer sheet says to:

Task 4: Create an event procedure for the Page_LoadComplete event.

Create an event procedure for the Page_LoadComplete event. In the InsertCustomer.aspx.vb code window, in the Object list, click (Page Events), and then in the Declarations list, click LoadComplete.

In VS 2010 I can't find the Object List - where would I find this?

I know I can type it in manually I just want to use the development editor to do the task as intended.




I am using SPHOL and I'm working on Lab3_EventHandlers.

Everything goes well until I try to deploy the event handler, and then I get a series of errors...

Could not find schema information for the element http://schemas.microsoft.com/sharepoint/:Receivers
Could not find schema information for the element "http://schemas.microsoft.com/sharepoint/:Receiver"
Could not find schema information for the element "http://schemas.microsoft.com/sharepoint/:Name"
Could not find schema information for the element "http://schemas.microsoft.com/sharepoint/:Type"
Could not find schema information for the element "http://schemas.microsoft.com/sharepoint/:SequenceNumber"
Could not find schema information for the element "http://schemas.microsoft.com/sharepoint/:Task"
Could not find schema information for the element http://schemas.microsoft.com/sharepoint/:Class"

Can anyone tell me how to fix this error?




I have recently downloaded the trial version of SQL server 2008 for self learning purposes and i am working through the tutorials. I have become stuck on the basic data mining tutorial lesson 5 (or 6?). I have created and tested 3 mining models using the MS decision trees, ms clustering and naive bayes algorithms (for the ASdatamining2008 targeted mailing structure) and now I am being asked to set a model filter on the tm_decision_trees mining model, to filter by gender. I have followed the steps and created a copy of the decision trees mining model and renamed it TM_decision_trees_male. so now i want to filter by gender. my problem is: when i have the Mining model i want selected and right click for the shortcut menu I dont seem to have access the SET MODEL FILTER option. It's there but "grey'd out", completly unselectable, the same with "create a new data mining dimension" and "set nested table row filter". The same occurs when i have selected a mining model and then clicked "mining model" menu on the task bar. Can u help?

-i have read that these options are not availible for the standard edition of SQL 2008 and only for the enterprise version. I of course have the downloaded trial version which i assume is not the same as the enterprise edition. Is this right or have i made a silly error somewhere when setting up the mining structure or somthing?


Matt (SS2008 novice)




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure