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.

substitution cipher help

by kangarooblood at 02:58 AM, 07/04/2009

Been trying to make a substitution cipher decrypter, but it isn't working especially good. so I thought I might could get some help with it.

#include <iostream>
#include <time.h>
#include <windows.h>
#include <iomanip.h>
#include <string.h>

using namespace std;

int main()
{
   
   
    bool EndThisShit(false);
    do {
    string input;
    cin >> input;
    int il;
    input.length() = il;
    int Ninput[il];
    Ninput[il] = input
    int y;
    for( y = 0; y < il; y++){
    int t =1;
    Ninput[fo] + t;
    i++;
    t++;
}
 int a;
 for(a = 0; a < il; a++) {
      enum letter {  a = 97, b, c, d, e, f, g, h, i, j, k, l, m, n, o , p, q, r, s, t, u ,v, w ,x ,y ,z};
      int b = 0;
      cout Ninput[b]
      b++;
      }   
      cout << " is this a good solution? y/n >> ";
      char yn;
      cin >> yn;
      if(yn == y) {
            EndThisShit = true;
            }
      if(yn == n) {
            EndThisShit = false;
            }
}while(!EndThisShit);
}

please help

by silent prince at 00:51 AM, 07/04/2009

i need ur help to write c++ porgram...
this is the topic of it
""""" Write a C++ program that calculates the perimeter and area of simple geometrical shapes based on the user’s selection. Let the program handle the perimeter and area calculations for circles, and Parallelograms. The program should display a menu of the three shapes, and then allow the user to select one of the options. Accordingly, the program would request from the user to enter the required parameters of the corresponding geometrical shape in floating-point form (e.g., radius of a circle). The program should interact with the user in a friendly way using a menu such as the following:
C: Circle.
P: Parallelogram.
The program should detect invalid inputs and display appropriate message to the user, accordingly. The following table describes the required parameters and the formulas for finding the perimeter and area for each shape.
Circle
Parallelogram
Parameters
Radius r
Sides S1 and S2
Angle α
Perimeter
2 π r
2(S1 + S2)
0 < α ≤ 90: (S1*S2)sinα
Area
π r2
90 < α ≤ 180: (S1*S2)sin(180-α)
Notes: S1 S2 H = S2 Sin α γ α
Assume π = 3.143;
Parallelogram Area = S1 * H = S1 * S2 * Sinγ
where, γ = 180 - α """



pleeeeeeeaaaassssssssssssse help

a c++ solution

by tag5 at 00:46 AM, 07/04/2009

Good, morning every one, in this nice forum;

I solved a c++ solution but i don't understand the idea of the program,
so i need help to understand the steps and the use of this program.
Thankyou,
all.

[c++] ISO C++ forbids declaration of _ with no type

by genepi at 00:28 AM, 07/04/2009

class C1{
public:
    C1(const C2& c){  //line 14 (works fine if i remove this constructor)
    //...
    }
};

class C2{
public:
    C2(const C1& c){
    //...
    }
};

the compiler show me the following error:
prova.cpp:14: error: expected ‘,’ or ‘...’ before ‘&’ token
prova.cpp:14: error: ISO C++ forbids declaration of ‘C2’ with no type

Snagged yet again...

by _dragonwolf_ at 23:32 PM, 07/03/2009

Here we go again. As you can see, I have gotten much further. There are some elements however that I am unsure how to apply (i.e. bool tooMany). I haven't the slightest how to apply that. That is one snag that I have. Another, and the main one, is this:

The following code does work. It calls a file called "studentData.txt". Said file contains the ID#s and Scores on their own lines :
(id) 101
(score) 100
102
95
103
90
...
...
121
0

Now, if I comment that out and just have it read from the arrays that I have hardcoded it works great. I can't quite figure out how to compute the .txt items into the individual arrays to make it use those as opposed to the hardcoded arrays. One of my main issues with reading from a .txt file, is that the only way I know how is using the getline feature. Is there anything better?

Currently I have the code calling the .txt file.

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

using namespace std;
void printTable(int score[], int id[], int count);
void printGrade(int oneScore, float average);

void readStudentData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
{
        const int MAX_SIZE = 21;
        rss.open("studentData.txt");
        string line;
        id[MAX_SIZE];
        int score[MAX_SIZE];
        count = 0;
        int oneScore = 0;
        float average = 0;
        string grade;

        for(count = 0; count < MAX_SIZE; count++)
        {
                getline(rss,line);
                cout << line;
                getline(rss,line);
                cout << "  " << line;
                cout << "  " << grade << endl;
        }

//        printTable(score, id, count);

}
float computeAverage(int scores[], int count[])
{
        const int MAX_SIZE = 21;

        return 0;
}
void printTable(int score[], int id[], int count)
{
        void printGrade(int oneScore, float average);
        const int MAX_SIZE = 21;
        int oneScore = 0;
        float average = 0;
        string grade;
        id[MAX_SIZE];
        score[MAX_SIZE];

        cout << left << setw(9) << "ID#s" << setw(9) << "Scores" << setw(9) << "Grades" << endl << endl;
        //for(count = 0; count < MAX_SIZE; count++)
        //{
                printGrade(oneScore,average);
        //}

}
void printGrade(int oneScore, float average)
{
        const int MAX_SIZE = 21;

        int id[MAX_SIZE] = {101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121};
        int scores[MAX_SIZE] = {100,95,90,85,80,75,70,65,60,55,50,45,40,35,30,25,20,15,10,5,0};
        oneScore = 0;
        average = 0;
        string grade;

        int sum = 0;
        for(int i = 0; i < MAX_SIZE; i++)
        sum += scores[i];
        average = sum / MAX_SIZE;

        for(int i = 0; i < MAX_SIZE; i++)
        {
                if(scores[i] > average + 10)
                {
                        grade = "outstanding";
                }
                else if(scores[i] < average - 10)
                {
                        grade = "unsatisfactory";
                }
                else
                {
                        grade = "satisfactory";
                }

//                cout << left << setw(9) << id[i] << setw(9) << scores[i] << setw(9) << grade << endl;
        }
       
}
int main()
{
        ifstream rss;
        string line;
        const int MAX_SIZE = 21;
        int scores[MAX_SIZE];
        int id[MAX_SIZE];
        int count;
        bool tooMany;

        readStudentData(rss, scores, id, count, tooMany);

       

        return 0;
}

Help with a vector<vector<string> *>

by squall1986 at 23:16 PM, 07/03/2009

Hi, for a class, I'm trying to implement a separate-chaining hash table stored in a vector that contains pointers to vectors where the keys will be stored. This is basically what I have:

    typedef vector<string> KeyChain;
    vector<KeyChain *> Table;

The problem I'm having is when I want to access the keys in the KeyChain, I don't know how to get to those values, this is what I've tried:
    Table[value][index]
    Table[value]->[index]

What is the syntax for accessing the items in a vector that is referenced with a pointer in another vector? Thank you for your help!

VC++ CODE

by balu naik at 22:22 PM, 07/03/2009

Haiiiiiiiiiiiii every one.
i am totally new for VC++ i need a program on vc++ window application.
i need to create a window, on that window i need 3 brouse button look like normal (file brouser) by using this button i need to get file path only.2 look like same and third button should be save as button.
plese help for this code.

Changing elements of lists

by wiczerd at 21:30 PM, 07/03/2009

I am reading lines from a CSV and don't know what size it'll be, so I place read lines into a list of a structure "obs". Then I want to iterate through this list, put it into another list and then modify contents of the original list so that I can print that later. I am, however, not sure if I'm actually modifying the original.

using namespace std;
struct obs{
        int date;
        int p;
        int attr_price;
        int q;
        double bcode;
        double uniq_store_id;
};

int main(){
        string line;
        ifstream fdata("jumboa_corrected.csv");
        obs last_obs;
        getline(fdata,line);
        int scanned = sscanf(line.c_str(),"%i,%i,%i, %lf, %lf",&last_obs.q,&last_obs.date,&last_obs.p,
                &last_obs.bcode,&last_obs.uniq_store_id);
        list<obs> this_series(1,last_obs);
        obs this_obs;
        while(getline(fdata,line)){
                ++gi;
                sscanf(line.c_str(),"%i, %i,%i, %lf, %lf",&this_obs.q,&this_obs.date,&this_obs.p,&this_obs.bcode,&this_obs.uniq_store_id);
                this_series.push_front(this_obs);

... stuff that fills in a bunch of this_obs into the list
        if(condition to start unloading){
                list<obs*> qtr_ser_obs;
                for (list<obs>::reverse_iterator it=this_series.rbegin() ; it != this_series.rend(); ++it )
                {
                        qtr_ser_obs.push_front(&*it);
                        for (list<obs*>::reverse_iterator qtr_obs_it =qtr_ser_obs.rbegin(); qtr_obs_it !=qtr_ser_obs.rend();qtr_obs_it++){
                                (*qtr_obs_it)->attr_price= computed_attr_price;
                        }
                  }
}

In this last line, what am I modifying?
Any help would be greatly appreciated. I guess I'm really not sure what is being placed with the line "
qtr_ser_obs.push_front(&*it);
"

how to round off using float

by taggz19 at 19:11 PM, 07/03/2009

i don't know how to make 1.6666667 to 1.6 only.. .

please someone help me. .

please! please! please!

C++ General Tree

by didijc at 18:04 PM, 07/03/2009

Hey C++ guru's...

I'm pretty new to the C++ world and would really appreciate some help... ...

I'm trying to build a general tree (a tree with one root and N children), I've written the code and compiled it quote/un-quote successfully... ...I say that because I am faced with a runtime error that basically stops my efforts dead in its tracks...

Attached to this is a screenshot of the runtime error...

/////// ********* GeneralTree.h *********///////
///////-------------------------------------///////
#ifndef GENERALTREE_h
#define GENERALTREE_h
 
#include <iostream>
 
using namespace std;
 
class GeneralTree{
        public:
                struct GenTreeNode{
                        int int_transactionID, int_totalNumChildren;
                        GenTreeNode *ptr_nextChild;
                };
               
                //initialize root
                GenTreeNode *root;
 
                GeneralTree(){
                        int int_totalNumChildren = 0;
                }
 
                ~GeneralTree(){
                        clear();
                }
 
                void clear(){
                        //point to the node to be deleted
                        GenTreeNode *tmp;
                        //used to visit each node in the tree.
                        //We start with the first actual node off of "root"
                        GenTreeNode *traverse = root->ptr_nextChild;
                       
                        //while the tree is not empty
                        while(traverse != NULL){
                                //store the current node
                                tmp = traverse;
                                //visit the next node
                                traverse = traverse->ptr_nextChild;
                                //free the memory taken up by the current node
                                delete tmp;
                        }
                }
 
                void addChildren(int *tranID, int cNo){
                        int int_totalNumChildren = cNo;
                        GenTreeNode *genTree = new GenTreeNode[int_totalNumChildren];
 
                        for(int i=0; i<int_totalNumChildren; i++){
                                genTree->int_transactionID = tranID[i];
                        }
                }
 
                void PrintTree(GenTreeNode *tree) {
                        /* .: Print all the items in the tree to which root points...the item in the root is printed first, followed by its children :: as long as the root is not empty :. */
                        if (tree != NULL){
                                cout << tree->int_transactionID << " ::- " << tree->int_totalNumChildren << endl;
                                // Print children
                                PrintTree(tree->ptr_nextChild);
                        }
                }
 
                void deleteChild(GenTreeNode *ChildPtr){
                }
};
 
#endif
 
/////// ********* Main.cpp *********///////
///////-------------------------------///////
#include <iostream>
#include <fstream>
#include "GeneralTree.h"
 
using namespace std;
 
int main(){
        GeneralTree *gTree = new GeneralTree;
        int tID = 100;
        int numOfChildren = 10;
 
        gTree->addChildren(&tID, numOfChildren);
        gTree->PrintTree(gTree->root);
 
        return 0;
}

Attached Images
File Type: jpg error.jpg (89.1 KB)

Program won't run outside Visual Studio 2008 Express

by OffbeatPatriot at 17:39 PM, 07/03/2009

I've made a program in Visual Studio, it's a gui meant to control a camera and the functions of it that my problem rotate about are the functions to open and close the link to the camera. The program seems to run but when I run the program outside visual studio(I double click on it in explorer) and open the camera the release version just closes and the debug version tells me a debug assertion failed,

Expression: _CrtIsValidHeapPointer(pUserData)

I'm not sure how to debug this because it runs fine in visual studio.

I'm kind of stumped and I hoped somebody could nudge me in the right direction based on this information. If I post the relevant code it'll be lengthy and it'll make many references other parts of code, and you might need to know something about pixci cameras.

Need help on homwork assignment.

by GooeyG at 16:38 PM, 07/03/2009

I need to create two enumerations, one for the months in the year and the other for birthstones.

Make a function named getBirthStone that returns the birthstone based on the month.
Jan-garnet
Feb-amethyst
Mar-aquamarine
Apr-diamond
May-emerald
June-pearl
July-ruby
Aug-peridot
Sep-sapphire
Oct-opal
Nov-topaz
Dec-turquoise

Add code to call the function when the user selects the display information option.

Include a menu item to the main menu to display all birth stones. Add code to call getBirthstone for each month.

I have started the assignment, but I'm not quite sure what I'm doing wrong. Any help is highly appreciated!!
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

Bstone::Bstone ( string );        // consructor intializes Bstone with string supplied as argument

int main()
{
        int name;        //the user's name
        int Bday;        //the user's birthday

        //prompting the user for their name
        cout << "Please enter your name:\n ";
        cin >> name;

        //prompting user for their birthday
        cout << "Please enter your birthday:\n ";
        cin >> Bday;

        //prompting the user to select one of the following.
        cout << "Please select the following, which you want to display:\n ";

        //beginning of the switch statement.
        switch (Useroptions)
        {
                case 1:        //displaying the user's birthstone.
                        cout << "Here is " << name << " birthstone \n";
                        cout << "His birthday is " << Bday;
                        break;
                case 2:        //displaying the user's astrogical sign.
                        cout << name << " astrogical sign is " << ....;
                        break;
                case 3:        //displaying the season of which the user's birthday occurs in.
                        cout << " The season in which " << name << " birthday occurs " << "....";
                        break;
                        default;
        }

        char Months, BirthStone;        // Months and Birthstones of the potential users
       
        // enumeration declaration for months
        enum Months { Jan = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };
       
        // enumeration declaration for birthstones
        enum BirthStone { GARNET = 1, AMETHYST, AQUAMARINE, DIAMOND, EMERALD, PERAL, RUBY, PERIDOT, SAPPHIRE, OPAL, TOPAZ, TURQUOISE };

        string Bstone::getBirthStone()
        {
        return Birthstone;
        }        //end function getbirthstone


return 0;
}

Tic Tac Toe

by PrincessT at 16:25 PM, 07/03/2009

I'm a beginner at c++ and I have to do a game of tic tac toe and I'm having problems with asking the player to play. Please help.

*****************************************************

#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

///function prototype
void inttableArray(int [][3], int );
void displayArray (int [][3], int );
void inputArrayFunction(int [][3], int );
void getMove(int [][3], int );
void getComputerMove(int [][3], int );
char Check(int [][3], int );


int main()
{
        char end;
       
       
        end= ' ';

        int tableOne[3][3]; //array of 3 row and 5 columns


        cout<<"This is the game of Tic Tac Toe.\n";
        cout<<"You will be playing against the computer.\n";


       
        inttableArray(tableOne, 3);

        displayArray(tableOne, 3);

        getMove(tableOne, 3);

        end = Check(tableOne, 3);

        getComputerMove(tableOne, 3);

        inputArrayFunction(tableOne, 3);

        if(end== ' ');
       
       
  if(end=='X') cout<<"You won!";
  else cout<<"I won!!!!";
  displayArray(tableOne, 3);


       
        return 1;

}

//**************************************************
void inttableArray(int TempArray[][3], int size )
{
        int row, column;

        for ( row = 0; row <3; row ++)
                for (column = 0; column < size; column ++)
                        TempArray[row][column] = ' ';
}

//**************************************************
void getMove(int TTempArray[][3], int Tsize)
{
        int x =0;
        int        y=0;
        int n=0;


  cout<<" Please make your move: ";
  cin>>n;

  if(n<1||n>9)
          cout<<"Invalid move"<<endl;
  else
          if(TTempArray[x][y]!= ' ')
        {
                cout<<"Invalid move, try again.\n";
                getMove(TTempArray, 3);
        }
        else TTempArray[x][y] = 'X';

       


}

//**************************************************

void getComputerMove(int STempArray[][3], int Ssize)
{
        int x;
        int        y;
        int n;


  cout<<"Player 2"<<endl;
  cout<<" Please make your move: ";
  cin>>n;

  if(n<1||n>9)
          cout<<"Invalid move"<<endl;
  else
          if(n=' ';n<=9);
        if(STempArray[y][x]!= ' ')
        {
                cout<<"Invalid move, try again.\n";
                getMove(STempArray, 3);
        }
        else STempArray[y][x] = 'Y';
}

//**************************************************
void displayArray (int DTempArray[][3], int Dsize)
{
        int x=0;
        int y=0;
       
               
        for ( x = 0; x < 3; x ++)
        {
                printf(" %c | %c | %c ",DTempArray[x][0],
            DTempArray[x][1], DTempArray [x][2]);
    if(x!=2) printf("\n---|---|---\n");
  }
  printf("\n");

       
}


//**************************************************
void inputArrayFunction(int inputArray[][3], int inputsize)
{
        int a, b;
        int x = 1;

        printf("\n---|---|---\n");

        for ( a = 0 ;a < 3; a++)
                for (b = 0; b < inputsize; b++)
                        if ( b == 2 )
                                inputArray[a][b] = 10;
                        else
                                inputArray[a][b] = b;
}
//**************************************************

char Check(int TinputArray[][3], int Tinputsize )
{
  int i;
  int row;
  int tableOne[3][3];
 
  for ( row = 0; row <3; row ++)
    if(tableOne[row][0]==tableOne[row][1] &&
      tableOne[row][0]==tableOne[row][2]) return tableOne[row][0];

  for(i=0; i<3; i++)
    if(tableOne[0][row]==tableOne[1][row] &&
      tableOne[0][row]==tableOne[2][row]) return tableOne[0][row];

 
  if(tableOne[0][0]==tableOne[1][1] &&
    tableOne[1][1]==tableOne[2][2])
      return tableOne[0][0];

  if(tableOne[0][2]==tableOne[1][1] &&
    tableOne[1][1]==tableOne[2][0])
      return tableOne[0][2];

  return ' ';
}

How to get a thread's execution time

by rmlopes at 09:24 AM, 07/03/2009

Hi everyone

I've been looking into boost and c++ reference, as well as some googling, and I cannot find a way to get a thread's execution time, all options I found are related to system time and I need only the execution time for the thread (inside the thread's context). Anyone knows how to get this?

Thanks in advance

Filename problem in Windows?

by VernonDozier at 09:22 AM, 07/03/2009

I'm pulling my hair out on this one. It's been a while since I've specified a path for an ofstream. I just want a simple file called "abc.txt" in the C: folder and I want to write "abc" to it. Anyone see anything wrong? Thanks.

#include <fstream>
using namespace std;


int main ()
{
    ofstream outs;
    outs.open ("C:\\abc.txt");
    outs << "abc";
    outs.close ();
    return 0;
}
2008 scandalz.net
Research is what I'm doing when I don't know what I'm doing. -- Wernher von Braun
CountryUS
IP Address38.103.63.59
User AgentCCBot/1.0 (+http://www.commoncrawl.org/bot.html)