|
Where are some good sites for a C ++ beginner to get code help at?
|
|
|
|
|
I heard about CodeProject... It seems to be a good one
Seriously, there is also CodeGuru (www.codeguru.com). For the others, I don't know, codeproject is enough for what I need
|
|
|
|
|
Hi, my name is jason
I am currently at a university takeing a c++ course and I AM SOOO LOST! =( I really could use some good adice from you guys!
Before I state my question, If anybody has AOL instant messenger my screen name is "imyoernme" and I would love to talk to u on it about my programs!!!!!! I would even consider using pay-pal to anybody who helps me succed in this class! You truely don' t understand HOW MUCH VALUE I CAN GET FROM YOU GUYS!
Ok...well here it goes.
This program that I am working on consists of the game "Connect four" It consits of three classes.
My first question is about our first class we are working on, its a MENU CLASS! This class is supposed to be a generic class and it should consist of nothing of the game. That is I can use this MENU class for other programs!
So far I have the menu.h and the menu.pp that I am working on!
Please can somebody help me!!! here are the directions for the menu class i got from my teacher.
___________________________________________________
[B]Menu class[/B]
Many programs use a menu to determine user choices. Your menu class should be generic, making it reusable in other programs you write.
Data Members:
an integer representing the number of choices on the menu
an array that can hold up to eight strings. Each string is one menu choice.
Methods (use the names given in bold and do not add any other methods):
a default constructor
a special constructor. The special constructor will take an int, indicating the number of choices in the menu, and eight strings. Each string will represent one menu choice. The last six strings will have default values of an empty string. This will allow the menu to handle from 2 to 8 menu choices.
run method to facilitate the menu processing and return the validated choice.
a helper method printMenu, and
a helper method validateChoice to read and validate the menu choice and return it.
Data Validation Requirements: Your menu should bring data in as characters, check that it is actually an integer within the expect range, convert it to an integer, and return an integer. See Technical Help for Program 2 for validation techniques
Here is my menu.cpp code...I don't know what to put for my validate choice desription!!! can anyone help? and the other empty ones!
#include <iostream>
#include <string>
#include "Menu.h"//includes Menu header file
//default constructor will initialize zero to the data private members (variables)
Menu::Menu()
{
numchoices = 0;
}
Menu::Menu(int c_numchoices, string str1, string str2, string str3, string str4,
string str5, string str6, string str7, string str8)
{
numchoices = c_numchoices;
MenuArr[0] = str1;
MenuArr[1] = str2;
MenuArr[2] = str3;
MenuArr[3] = str4;
MenuArr[4] = str5;
MenuArr[5] = str6;
MenuArr[6] = str7;
MenuArr[7] = str8;
}
int Menu::run()
{
printMenu();
validateChoice();
return choice;
}
void Menu::printMenu()
{
for(int i=0; i < numchoices; i++)//for loop
{
cout << i+1 << MenuArr[i] << endl;
}
}
int Menu::validateChoice()
{
char entry[1];
int choice;
do
{
}
PS...MY E-MAILL ADDRESS IS jdhooke@ilstu.edu Please e-mail for more help..that way I can connect with somebody and get through my class ....
|
|
|
|
|
Hi there.
First of all, no real world code would ever work like this. You would never have a fixed length array, for starters. If you must have a fixed length array, your paramaterless constructor should be private, otherwise you can build a menu that does nothing. Of what value is a menu with 0 choices ?
The int numChoices is not defined in this class. I assume it is private, so that it cannot be changed except by the constructor.
I don't see anywhere that you're actually accepting input from the user ?
Once you have a char, you can use atoi to turn it into an integer. You should initialise choice to -1 in validateChoice. I believe there is a function called IsAlpha, and one called IsAlphaNum in the C libraries, so if the character entered IsAlphaNum, and NOT IsAlpha, it must be a number.
You also have not defined the default values for the strings for menu choices 3-8.
ISUstudent wrote:
See Technical Help for Program 2 for validation techniques
Given that this is your core question, I must ask if you bothered to read this first ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
CHRISTIAN...THANK YOU SO MUCH TO REPLYING....
my e-mail address is jdhooke@ilstu.edu
If I can have your e-mail address I can sent to you the document my teacher gave me! she is really confusing the hell out of me!
Yes I am suppose to use atoi method, also, that was just the menu.cpp code. I have the header and I made everthing public so i can test it in a driver method..I need to use this class only and test it in the driver method!
PLEASE STAY IN TOUCH WITH ME AND HELP ME THROUGH THIS PROGRAM, I may even pay you some $$ for your help! I AM SERIOUS!!!!!
THANK YOU!
Please e-mail me!!!
~Jason
|
|
|
|
|
ISUstudent wrote:
...she is really confusing...
Which is usually a good indicator that you should either ask questions in class, or stop by her office after class for some specifics.
ISUstudent wrote:
PLEASE STAY IN TOUCH WITH ME AND HELP ME THROUGH THIS PROGRAM, I may even pay you some $$ for your help! I AM SERIOUS!!!!!
Begging is not very becoming. Ask your question(s). Be mature. Move on.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
Begging is not very becoming. Ask your question(s). Be mature. Move on.
ROTFL!!!!
|
|
|
|
|
hello jason,
try this one.
//======================================================
// menu.h
#include<iostream>
#include<string>
using namespace std;
class CMenu
{
private:
int m_numChoices;
string m_menuItem[8];
public:
// Default constructor
CMenu();
// Special constructor
CMenu(int itemcount,
string item1,
string item2,
string item3 = "",
string item4 = "",
string item5 = "",
string item6 = "",
string item7 = "",
string item8 = "");
void run(char item);
int validateChoice(char item);
void printMenu(int item);
};
//======================================================
//======================================================
// menu.cpp
#include "menu.h"
// Default contructor
CMenu::CMenu()
{
// Initialize the number of menu items
m_numChoices = 0;
}
CMenu::CMenu(int itemcount, string item1, string item2, string item3, string item4, string item5, string item6, string item7, string item8)
{
m_numChoices = 0;
// Process only if the number of requested items is correct
if((itemcount >= 2)&&(itemcount <= 8))
{
m_numChoices = itemcount;
m_menuItem[0] = item1;
m_menuItem[1] = item2;
m_menuItem[2] = item3;
m_menuItem[3] = item4;
m_menuItem[4] = item5;
m_menuItem[5] = item6;
m_menuItem[6] = item7;
m_menuItem[7] = item8;
}// if((itemcount >= 2)&&(itemcount <= 8))
}
void CMenu::run(char item)
{
printMenu(validateChoice(item));
}
int CMenu::validateChoice(char item)
{
int return_value = 0;
char *ptr_tmp = new char;
*ptr_tmp = item;
*(ptr_tmp+1) = 0;
int itmp = atoi(ptr_tmp);
//cout << endl << itmp << endl;
if((itmp >= 1) && (itmp <= m_numChoices))
{
// We need to subtract 1 because the m_menuItem array is zero-based
return_value = itmp - 1;
}
return return_value;
}
// Developer Note
// I am assuming that this method will print only
// the menu item corresponding to the
// integer location
void CMenu::printMenu(int item)
{
cout << m_menuItem[item];
}
//======================================================
// main.cpp
#include "menu.h"
void main()
{
CMenu oMenu(3, "item1", "item2", "item3");
oMenu.run('3');
}
//======================================================
Some notes, i assume this is only for your studies. becuase there are some major flaw in the design.
when you try:
CMenu menu();
this is actually useless.
anyway, hope this helps.
|
|
|
|
|
i missed something
the printMenu method should be:
void CMenu::printMenu(int item)
{
if(item > 0)
cout << m_menuItem[item];
}
cheers
|
|
|
|
|
It should be
<br />
void CMenu::printMenu(int item)<br />
{<br />
if(item > 0 && item<=m_numChoices)<br />
cout << m_menuItem[item-1];<br />
<br />
}<br />
and you need to initialise m_numchoices in the constructor.
Mike
|
|
|
|
|
thank you guys so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
I will see what I can do....that code is SOOOOO HELPFULL!!!!!!!!!!!!
I'M SURE I WILL BE BACK TO ASK MORE QUESTIONS!
~ JASON
|
|
|
|
|
OK, I am writing an MFC app using Visual C++ 6. The problem is, my program works in the release mode, but it doesn't work in the debug mode (yes, NOT the other way around!). I traced the problem, and it seems that the problem stems from one of my classes, which has a member variables like:
private:
.... some other things...
float number1[30];
float number2[30];
In this class' initialization, I use a for loop to initialize this array to all zeroes. The problem is, it seems that number2's address space overlaps with some other variables, and this overlap corrupts my program, causing some access violation (not debug assertion). This does not happen in the release mode. Could someone point to me how I can deal with this problem? Thanks!
|
|
|
|
|
Are you looping from 1 to 30, or from 0 to 29 ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am trying to read in a file, which was written using serialization (by someone else). The size of the variables present in the file from which I need to read is way greater than the stack size. So this is giving me problems like stack overflow. Is there any way to solve such problems? Please give me your suggestions .Thanks a lot
|
|
|
|
|
hemanth_phk wrote:
size of the variables present in the file...
Files don't have variables. A variable is something in your code that can contain the contents of the file, however.
hemanth_phk wrote:
...is way greater than the stack size.
Are you trying to read the file into a stack-based variable?
hemanth_phk wrote:
Is there any way to solve such problems?
Use memory from the heap instead.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I can't seem to open a listening socket on Windows Server 2003. The very same code has run on NT4 and Win2k for years. But when I try to run it on Win2k3, it fails to create a listening socket. The code is a C++ wrapper for the Windows Socket API (MFC Socket classes are mostly useless). I don't believe there is anything unusual about the way the code was implemented. It has never given us any trouble in the past.
I guess my question is this: Is there something more that I must know/do in order to run a socket server (i.e. listening socket) on Win2k3. Is this part of MS's Secure Computing Initiative. Or am I just overlooking the obvious? Any help would be greatly appreciated.
Thanks,
Jon
|
|
|
|
|
Win2k3 requires a listening socket to be bound to a specific IP, whereas Win2k and NT4 do not. We were not binding to a specific IP. One small change, and the code works on all 3 operating systems.
Jon
|
|
|
|
|
Hi,
We're getting the following error and we cannot figure out how to get rid of it. It is happening on only one person's pc and not others. The application(s) that he is compiling are simple MFC apps or even non-MFC apps. There is no use of ATL or COM. If anyone has any clues, please let us know. Thanks.
Regards,
Sanjeev
"fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>".
|
|
|
|
|
If you include any MFC header files after windows.h, then this error occures. For example:
#include "windows.h"
#include "afx.h"
The above code will cause C1189 error, but the following will not:
#include "afx.h"
#include "windows.h"
So, to avoid this error, make sure that you include windows.h at the end of all the includes.
Arsalan Malik
|
|
|
|
|
Arsalan Malik wrote:
#include "afx.h"
#include "windows.h"
So, to avoid this error, make sure that you include windows.h at the end of all the includes.
When using MFC, there's no reason to include windows.h as it has already been included.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi Folks,
Thanks for the tips but...
Please note that the compile error occurs on only one person's pc. If the project is compiled on someone else's pc, then there is no error.
Also, note that even on this one pc, the error only started occurring about a week ago. Previously, there was no such error. Nothing has been changed in the code.
It seems to me that maybe the wrong version of some file (probably .H) is being picked up from somewhere. I checked in the Tools - Options - Directories - Include files and it looks fine. This person has already uninstalled and re-installed Visual Studio without any success.
I'm hoping to find a solution for him before he goes re-formatting his drive .
Any other ideas? Please let me know. Thanks!!
-Sanjeev
|
|
|
|
|
skg747 wrote:
I checked in the Tools - Options - Directories - Include files and it looks fine.
What about the INCLUDE environment variable?
It's a long shot, but have you looked through the code for any #error directives?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
This is the only #error directive I see (in VC98\MFC\Include\afxv_w32.h):
#ifdef _WINDOWS_
#error WINDOWS.H already included. MFC apps must not #include <windows.h>
#endif
|
|
|
|
|
I'm trying to save a file to a server and getting a "The parameter is incorrect." exception.
<code>
CFile file;
CFileException ex;
if( file.Open(path, CFile::modeWrite | CFile::shareExclusive | CFile::modeCreate, &ex) )
{
try
{
CArchive ar(&file, CArchive::store);
ploan->Serialize(ar);
ar.Close();
file.Close();
}
catch(CFileException* pEx)
{
}
catch(CArchiveException* pEx)
{
}
catch(CException* pEx)
{
}
}
</code>
It creates a zero length file and fails. Any ideas??
Thanks!
ed
|
|
|
|
|
Does it happen if path points to some local (as opposed to a server) folder? Have you stepped into the CArchive constructor or the Serialize() method to see where the exception gets thrown? While the other two Close() methods can also throw an exception, I would rule them out for the time being.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|