C++ :: Defining Classes And Using Them Inside Void Main Function
May 18, 2013
This is a program I developed in which we had to define a class named BOOK with the data members and member functions as shown in the program..We have to:
(i) Make the user enter the values in the array BOOK.
(ii) Display the details that the user entered.
(iii) Search for a book from the array upon its Bno and display its details.
(iv) Search for a book from the array upon its Bname and display its details.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class BOOK {
private:
int Bno;
char Bname[20];
[Code] .....
But while running it the compiler gives the errors as:
Line 43 to 48: Illegal character '' (0x5c)
Line 69: Undefined symbol 'Display'
Line 88: 'BOOK::Bno' is not accessible.
Line 89:'BOOK::Bname' is not accessible.
Line 90:'BOOK::Author' is not accesible.
Line 91:'BOOK::Price' is not accesible.
Line 108:'BOOK::Bno' is not accessible.
Line 109:'BOOK::Bname' is not accessible.
Line 110:'BOOK::Author' is not accesible.
Line 111:'BOOK::Price' is not accesible.
from 43 to 48..the line feed was also used at many other places but there it was not given as an error so why here?
Line 69: I defined the Display() function outside the class since it contained control structures, so what's the error then?
About the lines the rest of the error( the "not accessible" ones) I know these data members are not accessible because they are in private visibility mode. But then how to make them accessible? (Without putting them in public because it was a part of the question to create the data members in private).
I have an array of (Student)classes created in Manager.h, which contains a new instance of class Name (name),(in Student.h)How would I go about accessing the SetFirstName method in Name.cpp if I was in a class Manager.cpp? I have tried using Students[i].name.SetFirstName("name");
// In Manager.h #include"Student.h" class Manager {
I want to make a thread outside an int main() method; and this code below gives an error of (paraphrasing) 'no constructor found for thread for type void()'
#include <thread>; class Board(){ //Lines Later
[Code]....
Is there any way to accomplish threading outside the main and in a class?
I've encountered a slight logical error in my code
/* Lab06_pensionplans.cpp Purpose : - Create a simple financial application to calculate retirement plans */ #include <iostream> #include <cstdlib> using namespace std; void displayMenu() { system("cls");
[Code] ....
Look at case 2, which the user supposed to key in a new input, the problem is the value will never got into main function, I don't know what should I modify with the function.
if possible i want avoid the '&' when i assign the variable address.(variant2 f=varname;//like you see i don't use the '&') for the moment i just need put the address to Variant pointer. but i receive several errors .
I am writing a program where all work is done in the class methods. Main is used to call the methods. I need to know how to get a loop to work without any variables in main that can be used outside the methods. This is what I have in main:
#include <iostream> #include <string> using namespace std; #include "FerryBoat.h" int main() { //create a constructor for a ferry boat FerryBoat myBoat('B', 20, 'A');
Code: class RaspberryPi: public Singleton<RaspberryPi> { private: static const DeviceInfo GPS; template<typename Register_t> auto ReadGPS(Register_t& Register) -> void
[Code] ....
There are two limitations I am facing:
First, it seems that anything that is part of a struct cannot be a compile-time expression. It's a nice way to group information, so it would be nice to have.
Secondly, it seems that all compile-time expressions cannot be inside a class (at least according to VC++), which means I have to move them to global level, but while it can be done, I don't really want to do it, because it's a platform detail.
In this case, static type dispatch would be nice to have because I have a function
There are two types of registers. With runtime dispatch, I get disgusting errors such as "could not deduce template arguments, blah blah" if some object doesn't have the required interface (i.e., don't have overloads for both register types). So the workaround would be to add two overloads and use something like asserts to stop invalid code from running, but it would be so nice to only allow correct code to compile and not get scary error messages.
I have two classes, a Package class and a Person class. The Package class has two Person objects has member variables, a Sender and a Receiver. While overloading the << operator for the Package class so that it will make an output label from everything in the Package class. Here is my code...
class Package{ public: Person Sender; Person Reciever; int weight; double cost; friend ostream &operator<<(ostream &out, Package &pack);
[Code] .....
So my problem is on that last output line, I am unable to call Sender.getName()... etc. Is there a proper syntax so that I can access the members of the Person class while overloading the << operator for the Package class?
I'm trying to define a 7x5 array in main and then use it in a different function that will fill that array with random floats between 0.0 and 1.0 and then use main to print the final, filled array.
I am work on building a simple parse tree and the layout of my code look like this:
Headers pt_node.hiterator.hparsetree.h
Source files node.cppparsetree.cppmain.cpp
I am still relatively new to C++ , and have been advised to include function definition for the member function of both pt_node class and iterator class in the node.cpp file
I particular I have declare the following iterator.h:
Basically, I have made a program which implements the platform specific layers (such as entry function, file loading, timing functions etc.) that gets compiled into a .exe (or platform equivalent).
But I want to make this portable and reusable across other projects, so the entry function for the platform will call the function "AppMain" which is the generic main function that is not reliant on the underlying platform etc. (i.e defined in a .h file that the project module will implement).
Ideally I would want to build the AppMain code into its own library. However, This AppMain code would want access to the Platform functions such as the functions compiled into the .exe.
This has confused me somewhat and has forced me to build both the AppMain module and the Platform Code into the same exe file so they can use each others functions.
Is there any way I can create a header file (with all the function prototypes in) but they do not get implemented in the Platform code but rather they can be 'guaranteed' to be available at runtime?
Here is what I am trying to achieve in a high level view:
win32layer.cpp: (implements all the functions defined in Platform.h)
in this scenario of course I could not compile the platform functions as the application has not been created and thus appmain cannot call the platform functions because that has not been created etc....
I'm trying to pass 2 arrays into a void funtion, and return values to one function.
this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.
#include <iostream> using namespace std; void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize); int main() { int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189}; int numberCount[8] = { 0 };
[code]...
The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.
Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.
void myKeyboardFunction(unsigned char key, int x, int y) { switch ( key ) {
[Code].....
But when I try to call it, trying to copy my previous method,
glutKeyboardFunc(Player1.playerControls);
I get an error
error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member
I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.
The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.
right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.
I was reading about void as function argument, but I did not fully understand it's meaning in C.
In C++ void foo(void) {} and void foo() {}
are the same. It means no arguments for foo function. But in C it's different. First function means the same as in C++, but second means
In C, an empty parameter list means that the number and type of the function arguments are unknown. But if it is unknown you can't use this arguments if user specifies same. Because here are no variables to store them. So doesn't result are the some? You do not get any arguments. O do I can get this arguments from some hidden variable?
For example.
void foo() { printf("%d", var); } foo(5);
It is very unclear for me. Do this apply to main function too?
int main(void) int main()
or can I use arguments given to int main() like given to int main(int argc, char* argv[])
i want to use a class to print data stored as vector or array with different data types. i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns. so i wrote the following class:
right now it has only one member function for printing two vectors. later i'll add additional functions as required.
note: there has to be template functions inside the class i also want the object to be global so that i need not pass it as an argument to other calling functions
then i want to call this template function in another ordinary function written in a seperate cpp file
these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions
i want to use a class to print data stored as vector or array with different data types.
i also want the print function two take more than one vector or array or combination of both so that they can be written to file as two columns.so i wrote the following class:
right now it has only one member function for printing two vectors. later i'll add additional functions as required.
note: there has to be template functions inside the class / i also want the object to be global so that i need not pass it as an argument to other calling functions
then i want to call this template function in another ordinary function written in a seperate cpp file these function declarations are put in a header file. so i need know whether i should put the declaration of the template function in the header to use the function in different functions.
I am writing a program in which a Fucntion has to be wriiten to parse the Command Line . When I include Code for parsing in main fuction iteslf ,its run ok . But I want to make a fucntion of that code and call it from main ,than it show Segmentation error .
By using Debugging I found Some thing is mess with " -m" Parameter of Command line , But Cant Rectify it ..
Code: int main (int argc, char *argv[]){ //get_parameter_value(argc,argv); // buffer[packet_size+1]= char ("'"); while (argc > 1) { if (argv[h][0] == '-')
int example (int [], int, *int,*int,*int,*int); int main () { My code will be here example (int array[], int size, &a,&b,&c,&d); // Like this??? I try it didnt work
I've been trying to get my program to call void functions with an if statement, but when i run my program and try to call one of the functions "worst case, best case, or random case" it doesn't get called. It just prompts the original menu.
#include<iostream> #include<fstream> using namespace std; void bubbleSort(); void selectionSort();