scandalz.net
 
 
 
BETA (Google AJAX Search)

Programming C/C++

I'm going to put some source code snippets and references here as I create and/or come accross them.

Disable/Enable Menu Items and Sub Items

by vickzbrit at 14:01 PM, 11/21/2008

How do I disable and Enable Menu Items and Sub Items.
if(Selected == "drum" || Selected == "guitar" || Selected == "mic" || Selected == "computer" || Selected == "car" || Selected == "hockey" || Selected == "laptop" || Selected == "watch" )
{
      pCmdUI->Enable(Sort == 1);
}

The above code used to work before having sub menu items to that menu item. After adding sub menu items, the previous code works for sub menu items but it would not work for menu item. Can anyone please help me out with this as where am i going wrong? Thank you

Vicky

How set fullscreen under win 2000 pro(console)?

by Icebone1000 at 11:36 AM, 11/21/2008

Hi, i was tring to figure how set display mode to fullscreen under win2000, i saw at msdn that theres a SetConsoleDisplayMode, but that is for winXP +..

I tried

                        //sets the console window
                        //to fullscreen
void FullScreen(){

        HANDLE consolehandle;

        int sysmetrics_x=GetSystemMetrics(SM_CXFULLSCREEN);//get full width
        int sysmetrics_y=GetSystemMetrics(SM_CYFULLSCREEN);//get full height

        COORD full_size;
                full_size.X= sysmetrics_x;
                full_size.Y= sysmetrics_y;

        consolehandle=GetStdHandle(STD_OUTPUT_HANDLE);

        SetConsoleScreenBufferSize(consolehandle, full_size);
       
}// F FullScreen

But that really doesn't set fullscreen mode...
o.o theres a special function for it?

please help, this is what i have done so far

by bids at 09:38 AM, 11/21/2008

 


#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
void serp(int level, int Ax, int Ay, int Bx, int By)
{
        int poly[4]={Ax,Ay,Bx,By};

        setfillstyle(SOLID_FILL,YELLOW);

        if (level>0)
        {

                serp(level-1, Ax,Ay ,(2*Ax+Bx)/3,(2*Ay+By)/3);
                serp(level-1,(2*Ax+Bx)/3,(2*Ay+By)/3,(Ax+Bx)/2+sqrt(3)*(Ay-By)/6,(Ay+By)/2+sqrt(3)*(Bx-Ax)/6);
                serp(level-1,(Ax+Bx)/2+sqrt(3)*(Ay-By)/6,(Ay+By)/2+sqrt(3)*(Bx-Ax)/6,(Ax+2*Bx)/3,(Ay+2*By)/3);
                serp(level-1,(Ax+2*Bx)/3,(Ay+2*By)/3,Bx,By);
        }
        else fillpoly(2,poly);
}

int main(void)
{
        int graphdriver=DETECT, graphmode;
        initgraph(&graphdriver, &graphmode, "");

        int i, N=8, Bx=0, By=235, Ax=635, Ay=235;

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

        serp(0,Ax,Ay,Bx,By);

        serp(1,Ax,Ay,Bx,By);
        serp(2,Ax,Ay,Bx,By);
        serp(3,Ax,Ay,Bx,By);
        serp(4,Ax,Ay,Bx,By);
        serp(5,Ax,Ay,Bx,By);
        serp(6,Ax,Ay,Bx,By);
        serp(7,Ax,Ay,Bx,By);

        delay(1000);
        cleardevice();
        }

        getch();
        closegraph();
        return 0;
}

what i could like to know is how do i fill each object with different colours?

What header do I look at for...

by Alex Edwards at 08:53 AM, 11/21/2008

In C++, where are the header files that define the standard primitives and bitfields?

I would like to confirm something, if it is possible.

-Alex

help with c++ coursework - code so far included.

by alexdm50 at 06:25 AM, 11/21/2008

hi im new to daniweb im currently working on a piece of work. the idea is to create a bank account with deposit and withdrawal functions. create student business and current accounts (this is all roughly done and a case of copying and pasting for each account type with a different set of questions) . what it requires me to do is allow 10 accounts to be opened and then allow the user to search for each one and deposit and withdraw from each one. would anyone have any suggestions on how i could do this. below is my code so far and thankyou for taking the time to look. also it requires me to take an object orientated approach and im rather confused what this entails, any suggestions again would be appreciated.

1st - BANK.CPP

#include <iostream>
#include <string> 

using namespace std;

int main()
{
// Declare Variables
        int withdraw;
        int sqone;
        int sqtwo;
        int bone;
        string colname;
        string name;
        string sname;
        int housenumber;
        string postcode;
        string dob;
        string telno;
        double acctbalance, deposit;
        char choices;
        acctbalance = 0;

//inputs, get the name and initial balance

         
        do
        {
cout<<"\n\n-------------------------------------------------\n"; 
cout << "What do you wish to do?" << endl; 
cout << "O open new account" << endl; 
cout << "C open new Business account" << endl; 
cout << "D Deposit Money" << endl; 
cout << "W Withdraw Money" << endl; 
cout << "B Display Balance" << endl; 
cout << "P Bank Account Details" << endl; 
cout << "Q Quit" << endl<<endl;cout<<"Enter selection: "; 
cin >> choices; 
switch (choices) 

//add account type options here under letter O 
case 'O': 
case 'o': 

    { 
        cout<<"\n\n-------------------------------------------------\n"; 
        cout << "What Account Do You Wish To Open?" << endl; 
        cout << "S Student Account" << endl; 
        cout << "C Current Account" << endl; 
        cout << "B Business Account" << endl; 
        cout<<"Enter selection: "; 
        cin >> choices; 
        break;// Need a break statement here 
    } 

                               
                               
                               
        //STUDENT ACCOUNT                       
                                case 'S':
                case 's':
                          {
                          cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
                          cout<<"---------------------------------------------------------"<<endl;
                                                  cout<<"Are You A Full Time Student?"<<endl;
                          cin>>sqone;
                          if (sqone == 0)
                          {
                                      cout << "sorry that is not a valid option"<< endl;
                                      break;
                          }
                                                  if (sqone == 2)
                          {
                                      cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                      break;
                          }
                          else if (sqone == 1)
                          {
                                      cout<<"Thankyou"<<endl;
                                                                          cout<<"Have You Got Documentation To Support Your Course And Accomadation?"<<endl;
                                                                                cin>>sqtwo;
                                                  if (sqtwo == 0)
                                                          {
                                      cout << "sorry that is not a valid option"<< endl;
                                      break;
                          }
                                                  if (sqtwo == 1)
                          {
                                                                                cout<<"Thankyou you are elegible for this account"<<endl;
                                                                                cout<<"------------------------------------------"<<endl;
                                                                                  cout << "Colleague Name: ";
                                                                                cin >> colname;
                                                                                cout << "Enter First Name: ";
                                                                                cin >> name;
                                                                                cout << "Enter Surname: ";
                                                                                cin >> sname;
                                                                                cout << "House Number: ";
                                                                                cin >> housenumber;
                                                                                cout << "Post Code: ";
                                                                                cin >> postcode;
                                                                                cout << "Date Of Birth: ";
                                                                                cin >> dob;
                                                                                cout << "Telephone Number: ";
                                                                                cin >> telno;
                                                                                cout << "Please enter initial balance: ";
                                                                                cin >> acctbalance;
                                                                                break;

                     
                          }
                                                        else if (sqtwo == 2)
                          {
                                      cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                      break;
                                                  }
                                               
               

          //BUSINESS ACCOUNT
                                                case 'c':
                case 'C':
                          {
                          cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
                          cout<<"---------------------------------------------------------"<<endl;
                                                  cout<<"Have you got documentation showing your business details?"<<endl;
                          cin>>bone;
                          if (bone == 0)
                          {
                                      cout << "sorry that is not a valid option"<< endl;
                                      break;
                          }
                                                  if (bone == 2)
                          {
                                      cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                      break;
                          }
                          if (bone == 1)
                          {
                                     
                                                                          cout<<"We Will Now Proceed To Open This Account For You?"<<endl;
                                                                                cout<<"------------------------------------------"<<endl;
                                                                                  cout << "Colleague Name: ";
                                                                                cin >> colname;
                                                                                cout << "Enter First Name: ";
                                                                                cin >> name;
                                                                                cout << "Enter Surname: ";
                                                                                cin >> sname;
                                                                                cout << "House Number: ";
                                                                                cin >> housenumber;
                                                                                cout << "Post Code: ";
                                                                                cin >> postcode;
                                                                                cout << "Date Of Birth: ";
                                                                                cin >> dob;
                                                                                cout << "Telephone Number: ";
                                                                                cin >> telno;
                                                                                cout << "Please enter initial balance: ";
                                                                                cin >> acctbalance;
                                                                                break;

                     
                          }
                                                        else if (sqtwo == 2)
                          {
                                      cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                      break;
                                                  }
                                                  }
                                                  }
                                                  }
               
                               
                               
                                case 'D':
                case 'd':
                          {
                          cout << "Enter amount to be deposited: "<< endl;
                          cin >>deposit;
                          if (deposit > 0)
                                      {
                                      acctbalance = acctbalance + deposit;
                                      if (deposit >= 10000)
                                      cout <<"Big Money!"<<endl;
                                      break;
                                      }
                          if (deposit == 0 || deposit < 0)
                                      {
                                      cout <<"Amount must be greater than 0";
                                      break ;
                                      }
                          }
                case 'B':
                case 'b':
                          {
                          cout <<"Your current balance is $ "<<acctbalance<<'.'<<endl;
                          if (acctbalance ==0)
                                          cout <<"Big Money!"<<endl;
                          break;
                          }
                case 'W':
                case 'w':
                          {
                          cout<<"Please enter amount to withdraw "<<endl;
                          cout<<"Withdrawal must be multiple of 10"<<endl;
                          cin>>withdraw;
                          if (withdraw == 00)
                          {
                                      cout << "Can't withdraw 0 dollars"<< endl;
                                      break;
                          }
                          if (withdraw < 0)
                          {
                                      cout<<"Must be a positive number"<<endl;
                                      break;
                          }
                          if (withdraw > acctbalance)
                          {
                                      cout<<"Can't withdraw more than balance"<<endl;
                                      break;
                          }
                          if ((withdraw % 10) !=0)
                          {
                                      cout<<"amount must be a multiple of 20"<<endl;
                                      break;
                          }
                          else
                          {
                                      acctbalance=acctbalance - withdraw;
                                      cout<<"Here is your money. Enjoy!"<< endl;
                                      break;
                          }
                                                  case 'P':
                case 'p':
                          {
                                                          cout << "\n\n"<<endl;
                                                          cout <<"Personal Details"<<endl;
                                                          cout <<"First Name : "<<name<<endl;
                                                          cout <<"Surname : " <<sname<<endl;
                                                          cout <<"house number : " <<housenumber<<endl;
                                                          cout <<"post code : " <<postcode<<endl;
                                                          cout <<"telephone number : " <<telno<<endl;

                          cout <<"Your current balance is £ "<<acctbalance<<'.'<<endl;
                          if (acctbalance ==0)
                                          cout <<"Big Money!"<<endl;
                          break;
                          }
                          }

                case 'Q':
                case 'q':
                          {
                                      cout<<"Thank for using our services have a nice day!"<<endl;
                                      break;
                          }
        }
        }while (choices != 'q' && choices != 'Q');
        return 0;
}

and the 2nd class - account.h
#include <iostream>
#include <string>

using namespace std;

class Account
{
  double money;        // amount of money held by this account
  double interestRate;  // a monthly or yearly interestrate, depending on how the account is to be used.


public:

    // create an account with an initial amountand a specified interest rate
  Account(double amount, double percent)
  {
    money = amount;
    interestRate = percent;
  }

    // return the account's balance
  double balance()
  {
    return money;
  }

    // add money to the account
  void deposit(double amount)
  {
    money += amount;
  }

    // substract money from the account
  void withdraw(double amount)
  {
   
  }

    // add money according to the interest rate.
  void addInterest()
  {
    money *= (1 + interestRate/100.0);
       
  }

};

thankyou again
#include<iostream.h>
int main()
{
int row1[10];
int col2[10];
int m,n,p,q;
cout<<"Enter the number of rows in matrix A"<<endl;
cin>>m;
cout<<"Enter the number of columns in matrix A"<<endl;
cin>>n;
cout<<"Enter the number of rows in matrix B"<<endl;
cin>>p;
cout<<"Enter the number of columns in matrix B"<<endl;
cin>>q;
if(n!=p)
{
int i=0;
cout<<"enter the rows of matrix1"<<endl;
for(i=0;i<=m;i++)
{
cin>>row1[i];
int *ptrow= &row1[0];
row1[i]= *(row1+i);
}
cout<<"enter the cols of matrix1"<<endl;
int k=0;
for(k=0;k<=;k++;)
{
cin>>row1[k];
int *ptcol2= &col2[0];
col2[k]= *(col2+k);
}
int matpro (int row1, int col2, int (*matpro)(int,int));
{
int pro[i][k];
for(i=0;i<m;i++;)
{
for(k=0;k<=q;q++)
{
pro[i][k]= row1[i] * col2[k];
int *ptpro= &pro[0];
pro[i][k] = *(pro+i);
pro++;
}
}
      cout << "[" << i << "][" << j << "]: " << pro[i][j];
return(pro[i][k]);
}
}
}

it is showing errors like

 expected primary-expression before ‘;’ token
27: error: expected `)' before ‘;’ token
27: error: expected primary-expression before ‘)’ token
:27: error: expected `;' before ‘)’ token
:36: error: expected `)' before ‘;’ token
:36: error: expected primary-expression before ‘)’ token
:36: error: expected `;' before ‘)’ token
:48: error: expected `}' at end of input
:48: error: expected `}' at end of input
48: error: expected `}' at end of input

Install Directory of another program

by maxicube at 06:02 AM, 11/21/2008

how would I get the install directory of another program, the registry perhaps? (using HLDS as my directory to be found) (GET HLDS HERE!)

i fond the key which might be useful. (how would i open it?
[HKEY_CURRENT_USER\Software\Valve\HLServer]
"InstallPath"="C:\\hlds"
"Full Name"="Half-Life Dedicated Server"
"Region"="5"

C++ / MFC Date Validation

by koushal.vv at 05:18 AM, 11/21/2008

Hi,


i just need to know is there any method in MFC / C++
which will do the validation for the entered date.
ie if the date 12/11/2008 is given as input it should return saying the date is valid.i hope there exsists some standard function.
it should also check for leap leap year,and wrong date such as 31/11/2008 etc. thanks in advance.

Help... Link list problem

by dapcigar at 01:04 AM, 11/21/2008

I've been trying to convert my Modular programming code from array to link list.. the whole program is kinda messy now.. could anyone help me figure out what problem am having with the code?

PS: am using Vc++6 to compile...
Thanks in Advance

Attached Files
File Type: cpp List.cpp (3.4 KB)
File Type: h List.h (568 Bytes)
File Type: cpp prompt.cpp (516 Bytes)
File Type: h prompt.h (247 Bytes)
File Type: cpp vcdDB.cpp (2.1 KB)
File Type: h vcdDB.h (1.3 KB)
File Type: cpp vcdrec.cpp (1.1 KB)
File Type: h vcdrec.h (629 Bytes)
File Type: cpp vcdmain.cpp (2.9 KB)

Help with instance of one class in another

by jbrock31 at 20:38 PM, 11/20/2008

Hello everyone.

I need help using an instance of a class in another. Below are two header files. NumDays.h and TimeOff.h

I need to have instances of the NumDays class in the TimeOff class as members. When i try to create the instance called maxSickDays, i do not get access to the NumDays member functions. What is wrong with my code? Thanks in advance.

NumDays.h
#ifndef NUMDAYS
#define NUMDAYS
#include <iostream>

class NumDays
{

private:
        int hours;
        float days;
        float calcDays();

public:
        NumDays()
        { hours = 0; days = 0.0; }

        void setHours(int hrs)
        { hours = hrs; }
        int getHours()
        { return hours; }
        float getDays();
       
        NumDays operator + ( const NumDays& );
        NumDays operator - ( const NumDays& );
        NumDays operator --();
        NumDays operator ++();
        NumDays operator ++ ( int );
        NumDays operator -- ( int );

};

#endif

and now TimeOff.H
#ifndef TIMEOFF
#define TIMEOFF
#include <iostream>
#include "NumDays.h"
#include <string>
using namespace std;

class TimeOff
{
private:
        string name;
        int idNum;
        NumDays maxSickDays;
               
public:
        TimeOff();
       

        void setName ( string n )
        { name = n; }
        void setIdNum ( int id )
        { idNum = id; }

        string getName()
        { return name; }
        int getIdNum()
        { return idNum; }
       
};

#endif

Thank you!

flashing characters (without clearing the screen)

by maxicube at 20:12 PM, 11/20/2008

OK, I'm making a backup application and once the backup is complete, I want it to flash
FINISHED!!!! - in different colours - any help at all would be appreciated, thanks - MaxICube

Linked List of struct

by number87 at 18:48 PM, 11/20/2008

I am creating a linked list which links a struct of data together. However, this is my problem, if I declare struct Node first then the Event type wont exist, but if I declare struct Event first then nodePtr wont exist....im kinda stuck here as to how I should declare them.

struct Event
{
      void addEvent();
     
      tm startTime, endTime;
      string eventItem;
      string eventNotes;
      char allDay;
      nodePtr head, tail;
                   
};


struct Node
{
      Event eventNode;
      Node *next;
};

typedef Node* nodePtr;

Space Invaders - Game

by emotionalone at 18:09 PM, 11/20/2008

I need to create a Space Invaders kind of game and I have a demo I need to copy the main features from. The invaders have to be of at least 3 different types and they change color.

So I figured the invaders are 3 child classes from a parent 'Invader' class that will have the methods of painting, moving, etc. What would be the best way to control the destruction of the invaders? I've read on this forum that a 'linked list' would be a way of doing just that. I don't know what a linked list is. So should I create an array that will store the position of the bullets (with a maximum of maybe 40 bullets). Is there a way to dynamically allocate memory for the bullets' position as they are created so I don't have an array of say 100 and use only 40?

The game will have sounds and the demo we've been given uses sound files located in the same folder the .exe is in, so they're not embedded (if that's how you would call it) or anything of that sort. The .exe is also got an icon.

We've been using PaintBox to draw stuff on application forms in Borland Builder so I think that's how it will be this time around too.

If you wish I can attach the demo folder.

Thanks in advance

ordering arrays

by 666kennedy at 16:53 PM, 11/20/2008

i have an array

weights[16][60]

this being 16 rows of 60 elements in each one

i have another

error[16]

which co incides with each with the 16 rows, this is the error from each row.

is there a way i can put each of the 16 in order in the array and then mimic that into the weights array so that all of those are like the ones in the error array?

help :S

by mstrofdrgns at 16:16 PM, 11/20/2008

hey there ,

Im taking C++ courses in my collage (so ım a newbie) and they are teaching programing language a bit different from the examples in this forum.
#include <stdio.h>


int main (void)
{
    int x;
    int y;
    int z;
    int min;
    printf("enter 3 numbers : ");
    scanf("%d %d %d", &x,&y,&z);
   
    min=x;
    if (y<x && y<z)
      y=min;
    if (z<x && z<y)
      z=min;

    printf("min is : ", min);
    return(0);
}
well this works too, but ı can not understand most of the programs in this forum

is there any place to learn how to write that " cout << ".... ; " thing or something like this :S
ty for helping this newcommer:)


/* sorry for my bad english ı hope u could understand what ı meant */
2008 scandalz.net
You or I must yield up his life to Ahrimanes. I would rather it were you. I should have no hesitation in sacrificing my own life to spare yours, but we take stock next week, and it would not be fair on the company. -- J. Wellington Wells
CountryUS
IP Address38.103.63.59
User AgentCCBot/1.0 (+http://www.commoncrawl.org/bot.html)