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).

View 1 Replies


ADVERTISEMENT

Visual C++ :: Access Violation Reading Void Assigned Dynamically Allocated Value Inside Function

Sep 16, 2013

Why the void pointer passed to testb doesn't continue pointing to the allocated integer after the function call returns.

Code:
#include <stdio.h>
#include <iostream>
void* testa() {
return new int(1);

[Code] ....

View 5 Replies View Related

C++ :: Array Of Classes With Classes Inside

Oct 5, 2013

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
{

[Code]....

View 2 Replies View Related

C/C++ :: Threading In Classes Instead Of Main?

Nov 1, 2013

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?

View 1 Replies View Related

C++ :: Logical Error - Change Value Inside Void Statement

Jul 16, 2013

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.

Figured out I need to change the

void changeData(int startingAge, int numOfYears,
double lumpSumAmount, double yearlyAmount, double interestRate )

into

void changeData(int &startingAge, int &numOfYears,
double &lumpSumAmount, double &yearlyAmount, double &interestRate )

View 2 Replies View Related

C++ :: Add Variable Address To Void Pointer Inside Of Class?

Dec 1, 2013

How can I add the variable adress to a void pointer inside of a class?

class variant2 {
private:
void *Vvariant=NULL;
public:
template<typename b>
variant & operator = (b *adress)

[Code] ....

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 .

View 4 Replies View Related

C++ :: Coding A Loop Inside A Class To Use In Main

Feb 22, 2013

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] ....

View 3 Replies View Related

C/C++ :: Difference Between Declaring Static Variable Inside And Outside Of Main

Apr 6, 2012

I want to know

prog1.c
#include<stdio.c>
static int c=6;
int main() {
/*code*/
}

prog2.c
#include<stdio.h>
int main(){
static int c=10;
}

what would be the difference between these two program in the fuctioning of static keyword ?

View 1 Replies View Related

C++ :: Static Type Dispatch With Structs Inside Classes?

Oct 15, 2013

I wanted to ask if it is somehow possible to do:

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

Code:
template<typename Register_t>
auto ReadBus(Platforms::DeviceInfo Device, Register_t& Register) -> void {
switch (Device.Bus)

[Code] .....

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.

View 5 Replies View Related

C++ :: Accessing Classes Member Variables Nested Inside Another Class

Feb 22, 2013

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?

View 2 Replies View Related

C :: Defining Array In One Function And Using It In The Next?

Nov 15, 2013

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.

Here is what I have so far:

Code:
#include <stdio.h>
#include <stdlib.h>
main () {
float array [7][5];
printf ("%f", array);

[Code] ....

I keep getting the following error message:

testinghw10.c: In function 'fillArray':
testinghw10.c:17: error: subscripted value is neither array nor pointer

I'm not sure what the problem is? Am I calling "array" variable incorrectly or did I initialize it wrong? Or something else entirely?

View 8 Replies View Related

C/C++ :: Defining Member Function In Different CPP File

Mar 27, 2014

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:

inline bool operator ==(const tree_iterator& rhs);

which is defined in node.cpp as:

inline bool tree_iterator::operator==(const tree_iterator& rhs) {
return (node ==rhs.node);
}

However on building I receive the following error:

undefined reference to `dnkmat001::tree_iterator::operator==(dnkmat001::tree_iterator const&)'

Why is this occurring and what measure can I take to fix my code

View 14 Replies View Related

C/C++ :: Not Able To Initialize Structure Variable Inside Main Whose Structure Defined GL

Aug 27, 2013

I am trying to run a programme implementing a function with structures in c... which is:

#include<stdio.h>
#include<conio.h>
struct store  {
        char name[20];
        float price;    
        int quantity;

[Code] .....

View 1 Replies View Related

C++ :: Defining Function Prototypes In Header File Without Implemented Body

Oct 6, 2014

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)

#include <AppMain.h>
int main(int argc, char** argv) {
//call AppMain
return AppMain(argc, argv);

[Code] ....

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....

Any way to overcome this?

View 9 Replies View Related

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

Feb 12, 2014

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.

View 6 Replies View Related

C++ :: Keyboard Function That Is Called In Main Function To Make Shape Move

Jan 19, 2013

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.

View 2 Replies View Related

C :: Main Function Does Not Return Any Values When Calling Other Function?

Jun 9, 2013

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.

Code:

#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {

[Code].....

View 4 Replies View Related

C++ :: Void As Function Argument

Mar 24, 2014

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[])

View 4 Replies View Related

C++ :: Using Template Function Inside Class In Separate Function?

Mar 26, 2014

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

class printdata
{
public:
template<typename T1,typename T2>
void SaveData( vector<T1> &data1,vector<T2> &data2, std::string var)
{

[Code]....

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

View 4 Replies View Related

C/C++ :: Using Template Function Inside A Class In Separate Function?

Mar 26, 2014

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

class printdata {
public:
template<typename T1,typename T2>
void SaveData( vector<T1> &data1,vector<T2> &data2, std::string var){
std::ofstream myfile;
std::string filename;

[code].....

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.

View 1 Replies View Related

C :: How To Pass Main Function Argument To Some Other Function

Dec 26, 2014

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] == '-')

[Code] .....

View 3 Replies View Related

C/C++ :: How To Get Formation From Pointer Function To Main Function

Feb 13, 2014

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

[Code] ....

View 2 Replies View Related

C++ :: Using Break In Void Function That Does Not Contain A Loop

Jan 14, 2015

I need this break in my main function, but I'm not allowed to put it in void since void is not located in a loop. How can I solve this?

Code:
#include <iostream>#include <string>
using namespace std;
void login(string x, string y);
string username;
string password;
string x;
string y;

[Code] ....

View 6 Replies View Related

C++ :: Multiplication Table In A Void Function?

Jan 20, 2015

I wanted to make a multiplication table.

Here's the code:

#include<iostream>
#include<conio.h>
using namespace std;
void initArray(int arg1[50][50], int r, int c) {
int val=1;
for(int row=0; row<r; row++) {

[code]....

I want the output to be like this:

1 2 3
2 4 6
3 6 9

If the user inputs 3 rows and 3 columns.

View 5 Replies View Related

C :: Program To Use Void Pointers In A Function

May 14, 2014

As part of my ongoing c programming education, I have written a program to use void pointers in a function,

Code:

#include <stdio.h>
#define MAX_NUMBERS 10
size_t size(void *object);
int main(void) {
}

[code]....

Now I think that the result 4 is the size of the pointer, so I'm confussed as why it doesn't give me the same result as 40.

View 2 Replies View Related

C++ :: If Statement - Void Function Not Calling

Nov 2, 2013

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();

[Code] .....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved