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

Assignment help with while loops

$
0
0
Hello:

I am doing an assignment for my computer science class, and was just hoping some on could check my work.

Here is a the assignment:

The population of a town A is less than the population of town B. However, the population of town A is growing faster than the population of town B. Write a program that prompts the user to enter the population and growth rate of each town. The program outputs after how many years the population of town A will be greater than or equal to the population of town B and the populations of both the towns at that time. (A sample input is: Population of town A = 5000, growth rate of town A = 4%, population of town B = 8000, and growth rate of town B = 2%.)

and here is my code:

#include <iostream>
using namespace std;

int main()
{
//variables
int pop_A, pop_B;
int year = 0; //counter variable
double growthrate_A, growthrate_B, newpop_A, newpop_B;

//Input
cout << "Enter the population of town A and town B: ";
cin >> pop_A >> pop_B;

cout << "Enter the growth rate town A and town B (growth rate B must be less than growth rate A): ";
cin >> growthrate_A >> growthrate_B;

//process

//error checking
while (pop_A >= pop_B)
{
cout << "Error: Population of Town A must be less than town B./n Please try again.";
cin >> pop_A;
}

//error checking
while (pop_A <= 0)
{
cout << "Error: Value must be greater than zero.\n Please try again.";
cin >> pop_A;
}

//error checking
while (pop_B <= 0)
{
cout << "Error: Value must be greater than zero. \n Please try again.";
cin >> pop_B;
}

//error checking
while (growthrate_A <= 0)
{
cout << "Error: Value must be greater than zero. \n Please try again.";
cin >> growthrate_A;
}

//error checking
while (growthrate_B <= 0)
{
cout << "Error: Value must be greater than zero. \n Please try again.";
cin >> growthrate_B;
}

//error checking
while (growthrate_A <= growthrate_B)
{
cout << "Error: The growth rate of town A must be greater than the growth rate of town B. \n Please try again.";
cin >> growthrate_A;
}

// calculating the new population by means of a while loop nested within an if-statement
if (growthrate_A > growthrate_B)
{
newpop_A = ((growthrate_A / 100) * pop_A) + pop_A;
newpop_B = ((growthrate_B / 100) * pop_B) + pop_B;

while (pop_A <= pop_B)
{
year += 1;

pop_A = ((growthrate_A / 100) * pop_A) + pop_A;
pop_B = ((growthrate_B / 100) * pop_B) + pop_B;
}
//output
cout << "The number of years it will take for town A population to be equal or greater than the population of town B is: " << year << endl;
}
system("pause");
return 0;
}


Thanks in advance. I greatly appreciate your input.
Attached Files

drive powered down??

$
0
0
I'm not sure if mine is a windows question or a C++/MFC question, but it is making me crazy. I am trying to solve a problem where a drive spins down "at a bad time". It occurs during a game, where a 3-second delay is a real problem. I tried writing a little program to determine how reading cached data affects when a drive powers down. Right now, I cannot seem to get the drive to power up when I expect it to. I have a hard drive with a 32MB cache. I first create a 1mb reference file and 1024 more files of the same size. All 1025 files have 1MB strings of random characters and the strings of characters are different from each other, My intention is to fill the files with data that cannot easily be compressed. I then read each of the 1024 files 3 times, leaving the first file untouched. My intention is to make sure that whatever cache there is does not contain anything related to my first file. BTW, after writing each file, I delete the CFile object. The program then loops through a process, where it tests the power state of the drive every second until it spins down. I then read the original file, thinking that the drive will need to power up to retrieve the data. The drive does read the data into the buffer (1024 reads of 1024 characters), but the drive is still powered down. If I try to do anything else, like delete the files, I can hear the drive power up. I have no idea where the data came from. Any ideas?

Thank you.

IntelliSense: a value of type "LPVOID" cannot be assigned to an entity of type

$
0
0
How solve this?

I have this sintaxe:

Code:


void(*sleep)(DWORD);


// and after:

sleep = VirtualAlloc(0, 12, MEM_COMMIT, PAGE_READWRITE); // Error is here

Ilustration for error: http://i.imgur.com/3IEYRal.png

want to write Client/Server Application for streaming of Videos

$
0
0
I have few training videos.I want to write a Client Server application to stream those videos on desktop.Server will keep listening to multiple client requests and based on client's request server will return video data.

Client Application dialog will show the list of Videos Available with Server.After clicking a video streaming of data should begin from Server and Client application could show that Video.Similar to youtube but not on web.

I am planning to write Multithreaded Server and Client and for connection will be using Sockets and for storing the path of videos in backend will use MYSQL.

Please share your thoughts on my approach or if you have any better suggestions please share it.

Is there any code available in C/C++ for streaming of Videos?

Thanks in Advance,
Vineet

Win32 PropertySheet and Stacked Tabs

$
0
0
Hello, I have a small problem.

I'm using Win32 PropertySheet function to create a static property sheety dialog. If I create a couple sheets, the tabs stay on the same line. However, if I create a dozen or so sheets, the tabs now show up in a stacked arrangement.

Question is, how do I stop Win32 from stacking the tabs?

I do realize that CPropertySheet has a class member called EnableStackedTabs(), however, I'm not using it. I would like to use the Win32 version. I searched the flag settings in both PROPSHEETHEADER and PROPSHEETPAGE, but I can't find any mention of stacked tabs or how to disable it.

Any ideas?

The linker cannot find the file I didn't specify in my project?

$
0
0
How can I create a program that is partially dynamically linked, and some parts set to statically linked (like some third party libraries)?
Thanks
Jack

What are all the meanings of Runtime library /MD /MT etc and the file it prodiuces.

$
0
0
I notice there are two options in the project settings in a Visual C++ project that
might be related
1) producing a dll file, debug/release multi-threaded DLL runtime library
2) producing a dll file, debug/release multi-threaded
3) producing a lib file, debug/release multi-threaded DLL runtime library
4) producing a lib file, debug/rrelease multi-threaded

What are all these combinations mean?

Thanks
Jack

[RESOLVED] I am trying to figure out why I am receiving "unresolved external symbol"

$
0
0
This message is appearing for each of my functions. Could someone explain what the issue is and how to fix it/ prevent it in the future?
Thank You. Here is my code:

Code:

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

struct airport
{
        float numLanded;
        float numDeparted;
        float greatestLanded;
        float leastLanded;
};

float averageDeparture(airport, int);
float averageLanded(airport, int);
int greatestLanded(airport, int);
int leastLanded(airport, int);


int main()
{
        string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
        airport statistics[12];
        int totalLanded = 0;
        int totalDeparted = 0;
        int count;
       
                for (count = 9; count < 12; count++)
                {
                        cout << "Please enter the number of planes that landed in " << months[count] << ": " << endl;
                        cin >> statistics[count].numLanded;
                        cout << "Please enter the number of planes that departed in " << months[count] << ": " << endl;
                        cin >> statistics[count].numDeparted;
                        cout << "Please enter the greatest number of planes that landed on a single day in " << months[count] << ": " << endl;
                        cin >> statistics[count].greatestLanded;

                       
                       
                        totalLanded += statistics[count].numLanded;
                        totalDeparted += statistics[count].numDeparted;
                }
               
       

        cout << "The average monthly landings for the year is " << averageDeparture(statistics[count], count) << endl;
        cout << "The average monthly departures for the year is " << averageLanded(statistics[count], count) << endl;
        cout << "The total landings for the year is " << totalLanded << endl;
        cout << "The total departures for the year is " << totalDeparted << endl;
        cout << "The greatest number of planes that landed in a single day is " << greatestLanded(statistics[count], count) << " which occured in the month of " << months[count] << endl;
        cout << "The least number of planes that landed in a single day is " << leastLanded(statistics[count], count) << " which occured in the month of " << months[count] << endl;

        system("pause");
        return 0;
}

float averageDeparture(airport array[], int pos)
{
        float total = array[pos].numDeparted;
       
        return (total / 3);
       
}

float averageLanded(airport array[], int pos)
{
        float total = array[pos].numDeparted;
       

        return (total / 3);

}

int greatestLanded(airport array[], int pos)
{
        int max = 0;
        for (int i = 1; i < pos; i++)
        {
                if (array[i].numLanded > array[i + 1].numLanded)
                {
                        max = array[i].numLanded;
                        return max;
                }
        }
}

int leastLanded(airport array[], int pos)
{
        int min = 0;
        for (int i = 1; i < pos; i++)
        {
                if (array[i].numLanded < array[i + 1].numLanded)
                {
                        min = array[i].numLanded;
                        return min;
                }
        }
}


Are there any tutorials/tools on teaching how to patch C++ project.

$
0
0
I have obtained a patch from boost for version 1.55 that applies so that it can be built under visual studio 2013.
I wonder if there are any tutorials on how to go about patching the source code?
Thanks
Jack

Subclassing ActiveX Control window in MFC

$
0
0
I am hosting the WebBrowser control in MFC.
I am developing WYSIWYG.

I have to subclass the Activex window to change the cursor while drag & drop event.

I did like this.

CComQIPtr<IOleWindow> pOleWindow = m_pWebBrowser2;
HWND hWnd = NULL;
HRESULT hr = pOleWindow->get_Wnd(&hWnd);

//CMyWnd is drived from CWnd, m_wnd is of type CMyWnd
m_wnd.SubclassWindow(hWnd);
//It is crashing inside MFC code where ASSERT(FromHandlePermanent(hWnd) == NULL)

Please help

Also anybody knows any link for useful source code for WYSIWYG in C++?

Prevent kill my software though Task Manager.

$
0
0
Hi,

I found a code that promises intercept and detour calls for TerminateProcess api and prevent kill my software directly across of Task Manager, but this don't is working and I can kill my process stilly across of Task Manager.

Here is the found code:

Code:


//////////////////////////////////////
//Project: TerminateProcess Hook    //
//Author: The-Eu4eH                //
//Date: 3/08/09                    //
//Credits: Azorbix (DetourFunc)    //
//        MSDN (Infomation Heaven) //
//////////////////////////////////////
 
#include <windows.h>
#include <iostream>
 
typedef bool (WINAPI *tTerminateProcess)(HANDLE, UINT);
tTerminateProcess oTerminateProcess;
 
bool WINAPI hkTerminateProcess(HANDLE hProcess, UINT uExitCode)
{
    MessageBox( NULL, "Hello from the hooked Term. Process!", "Hiiiiyyyaaa", MB_OK);
    std::cout << "Yay it worked!";
    return 1;
}
 
/* Can you show me the what the src, dst, and the jmp BYTE actually
contains after each step? So, I can understand it? Thanks, man.*/
 
void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
    BYTE *jmp = (BYTE*)malloc(len+5);
    DWORD dwback;
 
    VirtualProtect(src, len, PAGE_READWRITE, &dwback);
 
    memcpy(jmp, src, len);   
        jmp += len;
 
    jmp[0] = 0xE9;
    *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5; //this
 
    src[0] = 0xE9;
    *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;//this
     
    VirtualProtect(src, len, dwback, &dwback);
 
    return (jmp-len);//this
}
 
 
int main()
{
    std::cout << "Lets hook Terminate Process today." << std::endl;
    //Sleep(1500);
 
        //TerminateProcess(NULL, 0);
 
    oTerminateProcess = (tTerminateProcess)DetourFunc(
            (BYTE*)GetProcAddress(GetModuleHandle("kernel32.dll"), "TerminateProcess"),
            (BYTE*)hkTerminateProcess,
            5);
    if(oTerminateProcess == NULL)
    {
        std::cout << "Could not hook TerminateProcess." << std::endl; //
        return -2;
    }
 
    HMODULE hCurrentApp = GetModuleHandle(NULL);
    if(TerminateProcess(hCurrentApp, 0) != 0)
    {
        return 0;
    }
    else
    {
        return -3;
    }
}

I'm using this code in a dll, and putting on Form_Load event on Windows Form, also I already have tried inside a Thread with a loop (While True) and not solved nothing:

Someone can help me, saying me where I'm making wrong?

My computer works with:

system Windows 7 Ultimate 64 Bits

Thanks in advance.

How do i make a transparent richtextbox in visual c++ (visual studio express 2010)?

$
0
0
Hi everyone I'm new here! I'm looking to find a way to make a transparent richtextbox in visual c++. I've searched everywhere, the forums and the net but nothing seems to work. 99% of what I've found is in VB and C# which i can't seem to convert either. So who can help me?

Strange Behaviour of Release Mode

$
0
0
Hi ..

Today I needed to reopen my old project on Visual Studio 6 .. MFC AppWizard.

I modified a Dialog in that. I added Edit Control and Check Box . Added Member variables and relevant code.

I compiled it and Run.

The Modified Dialog is working fine in Debug Mode.

But my release mode is showing the same old dialog. It is not displaying the added items.

I struggled a lot . Build All 2/3 times .. no use. Checked class info and dialog properties.

I have added a completely new dialog

One thing , i installed service pack3 recently. Is that making any difference ?

Why this is happening ?

How Can I Refer To A New Page In Windows Store Universal App(Visual C++) ?

$
0
0
I'm new to windows app developing.
I created project in visual studio 2015 under visual c++ universal store app.
I added a new page from

project>add new item>xaml>basic page

I want to refer to the new page when I click a button in the main page.

my new page name is **BasicPage**

I added

#include "BasicPage.xaml.h"


and

using namespace Windows::UI::Xaml::Interop;


to the **MainPage.xaml.cpp**


and I added a button to mainpage and add this code to button click event

void Apptest_0_3::MainPage::button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if (this->Frame != nullptr)
{
this->Frame->Navigate(TypeName(BasicPage::typeid));
}

}



**How Can I fix this error?**

Thanks


http://i.stack.imgur.com/XGcj4.jpg

here is the screenshot of the error

http://i.stack.imgur.com/X4G9E.jpg

outer text of body element DHTML DOM

$
0
0
It is documented that outerText property of body element is only read only.

So if pHTMLElement is body element put_outerHTML will not work.

What is the solution for this?
I tried this way also but did not work

//CComBSTR bsSource;//bsSource contains the HTML code
CComPtr<Istream> pStream
::CreateStreamOnHGlobal(NULL,TRUE,&pStream);
CComQIPtr<IPersistStream> pPS = m_pWebBrowser2;//m_pWebBrowser2 is IWebBrowser2*
hr = bsSource.WriteToStream(pStream);
hr = pPS->Load(pStream);
Please help

Visual Studio 2010 Ultimate auto completion not working?

$
0
0
I type in the class name, the method can auto-complete, but the signature cannot.
Do I have to take a step further?
Thanks
Jack

CStatic doesn't work in CTab in MFC

$
0
0
Hello
I'm trying to change the text of a CStatic from a thread. I have a pointer to man dialog:
Code:

MDialog* MainDialog = (MDialog*)AfxGetApp()->m_pMainWnd;
then i try to change the text like this:
Code:

MainDialog->text1.SetWindowTextW(L"test1");
it will work if the text1 is placed in the dialog but not if its placed inside a tab but i can't figure out why ? :confused:
The code is in tab dialog .cpp not in main dialog but doesn't work anyway. I tried both ways
Any help would be greatly appreciated!

gluDisk problem

$
0
0
Hi ALL¡¡¡¡

I have a program wirh a lot of rotated cylinders. The use of gluDisk() for the extrems of everyone is giving me a problem.
When the program runs in a 'Debug' versión it Works.
When the program runs in a 'Release' versión it Works.
But in an executable versión, the program stopped and break, only in some PCs, not in all machines.

can someone help me please.
Thanka a lot¡¡¡¡
PERE

Some use of syntax won't compile on Visual Studio 2010

$
0
0
As I didn't write this code, I had no ideas what the original writer's intention was.
So I assume he was assigning the minimum allowed value of int to the first parameter
and max to the second.
But wasn't allowed on my side.
Code:

class IntAttribute : public SBAttribute
{
        public:
                SBAPI IntAttribute();
                SBAPI IntAttribute(const std::string& name, int val = 0, int minn = -std::numeric_limits<int>::max(), int maxx = std::numeric_limits<int>::max());

Code:

Error 1465        error C2589: '(' : illegal token on right side of '::'        D:\Programming\C++\3D\IK\SmartBody\core\smartbody\SmartBody\src\sb\SBAttribute.h        129        1        sbgui
Any ideas how to fix it?
Thanks
Jack

CDialog and Cdialogex link error

$
0
0
Hello,

I have a project in Visual C++, and it works well in Visual Studio 2005. I convert it to Visual Studio 2010, and everything went well, compiled and linked wihtout problems.

Then, I tried to add a new Dialog; the system added a Cdialogex (instead of the Cdialog that I used to use). I didin't realize that, and I go ahead, then compiled, and then I got a link error on all my previous Cdialog that I have:

Error 80 error LNK2001: símbolo externo "public: virtual void __thiscall CDialog::OnOK(void)" (?OnOK@CDialog@@UAEXXZ) sin resolver D:\proyectos010\MVFlexCGPlayer\VideoPlayConfigurationLE.obj

Any ideas about the problem?
Viewing all 3026 articles
Browse latest View live