Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3021 articles
Browse latest View live

cpu ID

$
0
0
If someone has (say) a quad-core CPU, do the cores have any kind of UID which can be interrogated by a program (i.e. to find out which core a given thread is running on)? Here's why...

I'm working on a cross-platform audio app which can load 3rd party plugins. Audio plugins can be notorious CPU hogs. The current version of our app doesn't have any support for multiple CPUs (except whatever's provided by the OS). So we often end up with multiple plugins (and everything else) all trying to share the first CPU core while the others sit there doing nothing. This can lead to problems such as audible glitching.

Someone's contributed some code which is supposed to overcome these problems by allocating plugins in a round-robin fashion to all the CPU's cores. I'm told that it works fine on Linux and OS-X. But from what I've observed in Windows it doesn't seem to work at all. The only way I could be certain would be if I could somehow print something out which would tell me what core the current thread is running on. I could then identify if the plugins are (or aren't) getting shared around the CPU cores. Anyone know of a way to do that?

How to capture mouse scroll for the CMFCRibbonEdit class?

$
0
0
For a ribbon bar with edit controls (CMFCRibbonEdit) I want to handle the mouse scroll events for the edit controls. That is, when the user clicks and then scrolls on the edit it will navigate a predefined list of strings. I want to capture the scroll event in order to update the edit text step by step.
This kind of behavior is implemented by the Spin Edit; I don't want to use the spin edit control since it only uses a list of integers and the spin buttons are too small.
Is there a way to catch the mouse scroll event for the CMFCRibbonEdit control? Please give some hints on how to approach message handling for the ribbon (other messages than the COMMAND allowed by the ribbon designer). I'm using VS2010 on Windows 7 and the ribbon was designed with the ribbon designer.
Thank you,
Cristi.

Free wmf editor

$
0
0
Hi¡
Please could someone recomends me a good free software editor, for wmf files.

Global variables little help pls

$
0
0
Hi guys I need help with my code this is my homework "Write a C++ program that will calculate the value of “e” (Euler’s number, e = 2.71828…) using a function you create named “find_e”. It shall have no arguments and return no values using the return statement. All transfer of information to and from the function must be in the form of global variables. The function “find_e” must be contained in a file separate file the file containing the “main” function . All output must be from the main program"

I made the program without global variables so you guys can see how it should look
/*#include <iostream>
#include <cmath>


using namespace std;

int main ()

{
double e;
double n;
double accuracy;
int euler = 2.7182818284590452353602874713527;

cout <<"insert the n value "<<endl;
cin>>n;

e=(1+1/n);
e=pow(e,n);


cout<<e<<endl;

accuracy=abs(euler-e);

cout<<"the accuracy is "<<accuracy<<endl;
system ("pause");

return 0;}
*/


and with global variables

this is my function.cpp

#include <iostream>


extern double n;
extern double e;
extern double accuracy;
double euler =2.7182818284590452353602874713527;


void f()
{

e=(1+1/n);
e=pow(e,n);

accuracy=abs(euler-e);

};

*/

and main.cpp

/*
#include <iostream>
#include <cmath>


using namespace std;

double n;
double e;
double accuracy;


int main ()

{


cout <<"insert the n value "<<endl;
cin>>n;


cout<<::e<<endl;



cout<<"the accuracy is "<<::accuracy<<endl;
system ("pause");

return 0;}

*/

I just get a 0 as answer D:

How to convert a C# module into an unmanaged C++ dll?

$
0
0
I am in need to convert some C# code into C++ equivalences.
But I don't want to spend the efforts to do so.
Is there an handy way to convert an existing code of C# into C++ (unmanaged code)?
if it's possible.
Any ideas?
Thanks
Jack

dynamic array resizing

$
0
0
I have to write a program where the user will input integer numbers. How many numbers they enter is unknown, therefor you should use a repetition structure for the input. When the user is done, they will enter -1 to exit.

Create a dynamic array if the size=2( the initial size must be 2)
Repeat until user enters -1.

I have to do this without using vectors.

This is what i have, I cannot figure out what to put in main. I was thinking of a do-while?

This is my first time in c++
Any hints?


Code:

#include <iostream>
using namespace std;
void resize(int *[], int);
int main()
{
        int *listDyn;
        int size=2;
        listDyn=new int[size];

       
                for (int i=0; i<size; i++)
                {
                        cout << "Enter as many integers as you'd like or enter -1 to exit" ;
                        cin >> listDyn[i];
                }


void resize(int *listDyn, int size)
{
        int *listDynNew=new int[size*2];
        for (int i=0; i<size; i++)
                listDynNew[i]=listDyn[i];
        size++;
        listDyn=listDynNew;
        delete[] listDynNew;
}

Displays arrays

$
0
0
I am trying to display the following arrays.

int a[4]={5,9,2,10}
int b[3][3]={1,2,3,4,5,6,7,8,9}
int c[2][3][2]={1,2,3,4,5,6,7,8,9,10,11,12}

Using these call statements
Display (a,4);
Display(b,3);
Display(c,2);

I'm not sure on how to put this all together but this is what I have so far.

Code:

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;


}
int a[4] = {5,9,2,10};
Display(a, 4);
void Display(int x[], int n)
{
for (int i = 0; i < n; ++i)
cout << x[i] << '\t';
}

int b[3][3] = { 1, 2, 3, 4, 5, 6,7,8,9 };
int total = Computetotal(b, 3)

int Computetotal(int x[][2], int n)
{
int t = o;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < 2; ++j)
{
t += x[i][j];
}
}
return t;
}

int c[2][3][2] = { 1, 2, 3, 4, 5,6,7,8,9,10,11,12}
int total = Computetotal(c, 2)
int Computetotal(int x[][2][4], int n)
{
int t = 0;
for (i = 0; i < n; ++i)
{
for (int j = 0; j < 2; ++j)
{
for (int k = 0; k < 4; ++k)
{
t += c[i][j][k];
}
}
}
return t;
}
}

Build failed

$
0
0
Name:  Ankush.jpg
Views: 1
Size:  20.5 KB
please help whenever i write any program output box shows build failed like this:-
================================================================================================================

1>------ Build started: Project: Practice, Configuration: Debug Win32 ------
1>Build started 22-Oct-14 9:06:48 AM.
1>PrepareForBuild:
1> Creating directory "E:\ANKUSH\Files\COMP. STUFF RELATED\Projects\Practice\Debug\".
1>InitializeBuildStatus:
1> Creating "Debug\Practice.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> Program to add two numbers.cpp
1>e:\ankush\files\comp. stuff related\projects\practice\practice\program to add two numbers.cpp(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.31
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

================================================================================================================

I AM USING MICROSOFT VISUAL 2010 (i have atached photo for more information)
pleaszzz help thank u :) :wave:
Attached Images
 

Monty Hall code problem

$
0
0
When i use option 2 in my code it says that I win 100% of the time and lose 0% of the time for some reason, I thought the logic looked correct but i"m not sure where I went wrong. If someone could help me out that would be appreciated!
Heres my Code.
Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int MontyHallGame(int b, int x);
int main()
{
    srand((unsigned)time(NULL));
    int option;
    int count=0;
    int wincount=0;
    printf("Menu:\n\n");
    printf("1.Game Mode\n");
    printf("2.Research Mode\n");
    printf("3.Exit\n");
    scanf("%d", &option);

    while (option!=3)
    {
        printf("\nGames played: %d\n", count);
        printf("Games won: %d\n\n", wincount);

        if (option==1)
                    {
                        int r=rand()%3;
                        if(r<3)
                            {
                                int b;
                                printf("Pick a door\n\n");
                                printf("1.Door 1\n");
                                printf("2.Door 2\n");
                                printf("3.Door 3\n");
                                scanf("%d", &b);

                                int x;
                                x=1;
                                printf("\nWould you like to switch doors?\n\n");
                                printf("1.Yes\n");
                                printf("2.No\n");
                                scanf("%d", &x);

                                int c;
                                int Prize;
                                c=MontyHallGame(b, x);
                                if(c==1)
                                {
                                    wincount++;
                                    count++;
                                    printf("\nCongratulations, the prize is behind this door, you win!\n");
                                }
                                else
                                {
                                    count++;
                                    printf("\nThe door is empty, you lose!\n");
                                }
                            }
                    }
            if (option==2)
                {
                    int a=-100;
                    printf("Please select your method for the simulation\n\n");
                    printf("1.Always Stay\n");
                    printf("2.Always Switch\n");
                    scanf("%d", &a);

                    int g=0;
                    int wins=0;
                    int loses=0;
                    int N;
                    float i;
                    float j;
                    int b;
                    int Prize;
                    int x;
                    int Gameruns;

                    printf("\nPlease enter a value for N\n");
                    scanf("%d", &N);
                    for (Gameruns=0; Gameruns<N; Gameruns++)
                        if (a==1)
                            {
                                b=1;
                                g=MontyHallGame(b, x);
                                if (g=1)
                                    wins++;
                                else
                                    loses++;
                            }
                        if (a==2)
                            {
                                b<=3;
                                g=MontyHallGame(b, x);
                                if (g=1)
                                    loses++;
                                else
                                    wins++;
                            }
                    i=(wins/N)*100;
                    j=(loses/N)*100;
                    printf("\nYou won %f percent of the time and lost %f percent of the time.\n", i, j);
                }
            printf("Menu:\n\n");
            printf("1.Game Mode\n");
            printf("2.Research Mode\n");
            printf("3.Exit\n");
            scanf("%d", &option);

        }
    return 0;
}

int MontyHallGame(int b, int x)
{
    int Prize;
    int win;
    Prize=rand()%3+1;
    if (x==1)
    {
        if (b==Prize)
            win=1;
        else
            win=0;
    }
    if (x==2)
    {
        if (b==Prize)
            win=0;
        else
            win=1;
    }
    return win;
}

Lab 3.c
Attached Files

Is it worthwhile to write an ActiveX module dedicated to drawing charts?

$
0
0
I know the user installation must involve some registry manipulations and
some other trickery. But the ActiveX way seems to be more modular.
Is it worthwhile to separate the charting modules from the exe and make an activex dll
for this purpose?
Thanks
Jack

Voting bot - every 50th entry wins

$
0
0
Hello everybody,

I am supposed to write a simple voting program as a semestral project. There are about 30 people in our class and we are going to compete with our voting bots against each other (+ some random traffic bots). The principle is simple - every 50th entry (vote) wins.

We are given the results website, where we can see winners and current vote count. Nothing more. Oh, and everybody has only 50 votes (except traffic bots).

I have already written voting function, function to extract the number of votes from the results website, function to find out server response time and made some voting bots to simulate traffic on the server (voting every 2s, 4s,..., randomly). But now I got stuck with the algorithm which should decide, when to vote.

I guess that most people in my class are going to use something like "if there are more than 45 votes and less than 50 -> vote" approach.

I was thinking about measuring average latency and average traffic for first few rounds but there are going to be many 'outliers' just before the 50th votes and based on my bots, the latency is going to drop rapidly (my 2s bot voted 10s late because the server couldn't handle the load). I just don't see the connection between vote count and server response and how to measure the right voting moment accurately.


Can you help me with the algorithm design please? I don't want you to do my project, I just need you to point me to the right direction. I believe this could be solved with some statistic method or machine learning but we haven't learned it yet.

Thank you

macro with mupltiple parameters

$
0
0
Keep in mind that in the following example, SET_DARKENING_PARAMETERS_0 is a fairly simple macro which accepts 9 parameters. The first one is called driver and the other 8 are all ints. Basically, the 8 x ints get assigned to the first 8 elements of an array which is owned by driver. I can call the macro successfully if I do this:-

Code:

SET_DARKENING_PARAMETERS_0 ( some_driver, 500, 400, 1000, 275, 1667, 275, 2333, 0 );
but in the actual code I'm trying to compile, the 8 x ints are themselves encoded into a secondary macro like this:-

Code:

#define CONFIG_OPTION_DARKENING_PARAMETERS 500, 400, 1000, 275, 1667, 275, 2333, 0
so the actual code (to call SET_DARKENING_PARAMETERS_0) looks like this:-

Code:

SET_DARKENING_PARAMETERS_0 ( some_driver, CONFIG_OPTION_DARKENING_PARAMETERS );
But the two combined macros won't compile with VC8. Basically, I get warning #C4003 (not enough parameters for macro 'SET_DARKENING_PARAMETERS_0') followed by a load of syntax errors. However, the code (allegedly) compiles with gcc.

I'm wondering if macro CONFIG_OPTION_DARKENING_PARAMETERS might be getting truncated to just 500, (with the following parameters getting ignored)? Or can anyone offer another explanation?

c++ weird error

$
0
0
[CODE]guys i'm having a weird error coming when i compile this program
it's a program to fill an array of 100 integers with random grades for 100 students in the range of 40-100, then calculate the average of the grades and the number of grades higher and lower than the average
any help please?

Code:

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
        srand(time(0));
   
        int list[100];
        double sum=0, average , GradesBelow=0, GradesAbove=0;

        for( int j=1; j<101; j++)
        {
                int i = rand()%61 + 40;
                list[j]=i;
                sum += list[j];

        }
        average = sum/100;

        for( int j=1; j < 101; j++)
        {
                int i = rand()%61 + 40;
                list[j] = i;

                if ( list[i] < average )
                {
                  GradesBelow++;
                }
               
                if ( list[i] > average )
                {
                        GradesAbove++;
                }
        }
 
                cout<< " The class average is : "<<average<<endl;
                cout<< " There are "<< GradesBelow << " grades below the average. "<<endl;
                cout<< " Also, there are "<< GradesAbove << " grades above the average. "<<endl;

                return 0;
}

Error in finding lowest double in an array

$
0
0
I just can't figure out why when I run the program, when it displays the lowest temtpature, it shows the address instead of the actual number. Any help? Thanks!
Code:

/**********************************************
* Project: hw7
* File: b.cpp
* Authors:
* Date: 10/24/2014
* Description: Create a C++ program that declares a 100-element array
of doubles representing temperature readings. Pass the array to a function
to be partially filled by the user. When the user is done entering temperatures,
the function should return the number of elements added to the array. The main
function should then display the maximum and minimum temperatures in the array.
***********************************************/
#include <iostream>


using namespace std;

//prototypes
void getData(double arr[]);

//global variable
const int SIZE = 100;

/********************************************************************
 * Function: main
 * Description: This function controls the flow of the program
 *              and calls all necessary functions.
 *******************************************************************/
int main()
{
        //variables
        double tempt[SIZE];
        double high = 0.0;
        double low = 0.0;

        //pass array to function
        getData(tempt);

        //get highest
        for (int i = 0; i < SIZE; i++)
        {
                if(tempt[i] > high)
                        high = tempt[i];
        }

        //get lowest
        for (int i = 0; i < SIZE; i++)
        {
                if(tempt[i] < low)
                        low = tempt[i];
        }

        //display
        cout << "The highest temptature is: " << high << endl;
        cout << "The lowest temptature is: " << low << endl;

        return 0;
}

//function that records the temptature and stores it in the array
void getData(double arr[])
{
        int count = 0;

        for (int i = 0; i < SIZE; i++)
        {
                cout << "Record a temptature: " ;
                cin >> arr[i];
                cin.clear();
                cin.ignore(100, '\n');
                cout << "Enter 2 if you'll like to add another(if no, enter 1): ";
                cin >> count;
                cin.clear();
                cin.ignore(100, '\n');
                if(count == 1)
                        break;
        }
}

[RESOLVED] Pass an array to a function and assort in descending order


How to get address of an selected image in string form

$
0
0
I have developed a form where i need to select an image from file explorer.
But, when i select an image using,

Code:

objOpenFileDialog->ShowDialog();
System::String^ imgName = objFileDialog->FileName;

it returns address in "String^" form.
Problem is that, i need in "String" to make some string operations like,

Code:

string path = imgName;
or
Code:

Mat img = imread(imgName, CV_LOAD_IMAGE_GRAYSCALE);
trim image full path to image name only etc...

How can i get path of an image in String format ???

C++ need help with class

$
0
0
Hello i am a beginner in c++ and i really need some help with my code. i keep getting 2 errors and im not sure how to fix them...
1. i keep getting that invoice2 is undeclared
2. expected ';' before "invoice2" (Each undeclared identifier is reported only once for each function it appears in.)

here my code

//.h file

#include <iostream>
#include <string>

using namespace std;

class invoice{

private:
string num;
string des;
int quantity;
int price;

public:
void setnum(string);
string getnum();

void setdes(string);
string getdes();

void setquantity(int);
int getquantity();

void setprice(int);
int getprice();

invoice();
invoice(string, string, int, int);


int getInvoiceAmount();






};


//cpp.file

#include "invoice.h"




invoice::invoice(string a, string b, int c, int d){
setnum(a);
setdes(b);
setquantity(c);
setprice(d);
}


void invoice::setnum(string a){
num=a;
}
string invoice::getnum(){
return num;
}

void invoice::setdes(string b){
des=b;
}
string invoice::getdes(){
return des;
}

void invoice::setquantity(int c){//loop until a positive number is assigned
quantity=c;

while(c<0){

if (c>=0)
quantity=c;

if(c<0){
cout << "ERROR: Quantity cannot be \nEnter Quantity: ";
cin>>c;
quantity=c;
}
}
}


int invoice::getquantity(){

return quantity;

}
void invoice::setprice(int d){//loop until a positve number is assigned
price = d;


while(d<0){

if (d>=0)
price=d;

if(d<0){
cout << "ERROR: PriceperItem cannot be negative.\nEnter PriceperItem: ";
cin>>d;
price=d;
}
}
}
int invoice::getprice(){

return price;

}
int invoice::getInvoiceAmount(){
return (getquantity()*getprice());
}


//main


#include "invoice.h"


int main(){

// create an Invoice object

invoice invoice( "12345", "Hammer", 100, 5 );


// display the invoice data members and calculate the amount
cout << "Part number: " << invoice.getnum() << endl;
cout << "Part description: " << invoice.getdes() << endl;
cout << "Quantity: " << invoice.getquantity() << endl;
cout << "Price per item: $" << invoice.getprice() << endl;
cout << "Invoice amount: $" << invoice.getInvoiceAmount() << endl;

// modify the invoice data members
invoice.setnum( "123456" );
invoice.setdes( "Saw" );
invoice.setquantity( -5 ); // negative quantity
invoice.setprice( 10 );
cout << "\nInvoice data members modified.\n\n";


// display the modified invoice data members and calculate new amount
cout << "Part number: " << invoice.getnum() << endl;
cout << "Part description: " << invoice.getdes() << endl;
cout << "Quantity: " << invoice.getquantity() << endl;
cout << "Price per item: $" << invoice.getprice() << endl;
cout << "Invoice amount: $" << invoice.getInvoiceAmount() << endl;

//Next Instance of Invoice Object
//Both quantity and price are negative

invoice invoice2("67890", "Drill", -8, -10);
cout << "\n\nNEXT INVOICE \n\n";

cout << "Part number: " << invoice2.getnum() << endl;
cout << "Part description: " << invoice2.getdes() << endl;
cout << "Quantity: " << invoice2.getquantity() << endl;
cout << "Price per item: $" << invoice2.getprice() << endl;
cout << "Invoice amount: $" << invoice2.getInvoiceAmount() << endl;





return 0;
}


any help would be great

CDialog resize in one direction

$
0
0
Is there any way to allow user to resize a CDialog only in one direction ? I mean, by width, but not by height ? How ? I noticed that overriding WM_SIZE, I can do nothing about this issue ...

quick question

$
0
0
Hi i want to fix this code.
The program must accept 7 values or stop it when you type s.
The code not only couts the element, but also some other random numbers.
Any help would be appreciated, thanks.

Code:

#include<iostream>

using namespace std;

int main()
{
        int numb[7];
        int i;
        char s;
        for (i=0;i<=6;i++)
        {
                cout << "Please enter number:";
                cin >> numb[i];
                while (i=='s');
        }

        for (i=0;i<=6;i++){

        cout <<endl<<numb[i]<<endl;
        }

system("pause");
return 0;

help I'm confused

Viewing all 3021 articles
Browse latest View live