C++ :: Displaying Variables From A Function Class

Feb 9, 2013

I am trying to display a variable from a class function the code works in debug but the variable is not displayed. Here is my code so far.

#include <iostream>
#include <string>
using namespace std;
class dayType {
public:
string day;
void setday(string);

[Code] .....

View 2 Replies


ADVERTISEMENT

C++ :: Function Does Not Update Class Variables In Recursive Call

Dec 14, 2014

I'm trying to implement Tarjan's Strongly Connected Components Algorithm in C++. Here's how I gotten so far:

void tarjan(vector<Vertex>& G){
index = 0;
while (!S.empty()) S.pop();

[Code]....

Here's an example graph for the algorithm to run: [URL]

Here's the first part of the output of the program: [URL]

all the index & lowlink values of the nodes are set to -1 in the beginning. global index value is set to 0. My problem is, the algorithm starts running on Vertex X-4. It runs the instruction X-4.index=0 & X-4.lowlink=0 then it calls itself with the paramater of node X-1. it sets X-1's index & lowlink values to 1. then it calls itself for X2. then it checks whether node X-4 has the index value <0 or not. Even though we set the value of X-4 to 0 in the first run, it still sees X-4.index as -1.

View 1 Replies View Related

C++ :: Displaying Month Names From Class

Apr 10, 2013

I am having trouble associating the month names with the month numbers. When the program runs, it should output the date in three styles.

Also I do not know if my input validations work correctly(day cannot be greater than 31 or less than 1, month cannot be greater than 12 or less than 1).

#include <iostream>
using namespace std;
char again;
class Date {
private:
int month;
int day;
int year;

[Code] ....

View 7 Replies View Related

C++ :: Displaying Function From Reference?

Aug 29, 2013

Having a little trouble getting my function to display the results. I got my getNumber function working and I know I can't use return to return multiple values so I created a function that would display my results but I am a little lost on how I get the results from one function to another.

#include <iostream>
#include <array>
#include <iomanip>
using namespace std;
void printResult(int, int);
void getNumber(int &, int &);
void printResults (int, int){
int n, n1;

[code].....

View 13 Replies View Related

C# :: Displaying Progress Bar While Other Parallel Function Running

May 19, 2014

I have a module that pings the network to find available devices using threading.

the money line:

var valids = range.AsParallel().AsOrdered().Where(ip => ip.Ping()).ToList();

The problem is, I need to display a progress bar while this function runs. I have the progress bar implemented with a background worker, but it won't update while the ping module is executing. I *think* it's because I'm using the available threads for the ping module.

When the user clicks a button, I need the ping module to run while the progress bar updates, or even just set IsIndeterminite to true. What would be the best way to accomplish this?

View 4 Replies View Related

C :: Recursive Function Not Displaying Correct Sequence Request

Jul 1, 2013

Ok, so the assignment is to use a recursive function to display a request for a certain position in the Fibonacci Sequence (0, 1, 1, 2, 3, 5, 8, 13...)

The program I have written works, but it displays the wrong number in sequence. The book says that when you enter "8" you should receive "13", which is correct in the order of the sequence, though my program is producing "21" which is the next number in the sequence.

I tested it with a few more numbers and when I enter "7" it produces "13" and when I enter "6" it produces "8" and so on.

Code:
//Cameron Taylor
#include <stdio.h>
int main(){

[Code].....

View 2 Replies View Related

C++ :: Initializing Variables In Each Class

Sep 26, 2014

I am working on a homework assignment and have most of the program working, but when I try to compile it keeps telling me to initialize the coin variables in each class. However, they are supposed to be added then removed so I don't want to set them back to zero.

Rewrite the Purse program given in Page 35 with functions to perform insert and remove operations. The function insert (int p, int n, int d, int q) will initialize pennies, nickels, dimes and quarters. The function dollars() will return the dollars. The function remove (int p, int n, int d, int q) will subtract pennies, nickels, dimes and quarters. The function display() returns a new String to print the content of the purse with remaining pennies, nickels, dimes and quarters.

Code:
usingnamespace std;
int insert_money (int *p, int *n, int *d, int *q);
int remove_money (int *p, int *n, int *d, int *q);
int dollars();
int main()

[Code] ....

View 2 Replies View Related

C++ :: Accessing Variables Of Another Class?

Aug 3, 2013

I've been attempting to create a game with curses and I keep running into the problem of scope. I want to change or use variables of a different class in a different header file. But I don't know if I should use pointers, references or neither. Should I be programming in a manner that doesn't make it necessary to use variables outside of their class?

View 1 Replies View Related

C++ :: Change Value Of Instance Variables From Another Class?

May 6, 2014

I'm trying to change the values of some instance variables in my Controller Class so that when the user inserts values into main class it changes for Controller.

class Controller {
public:
Controller();
~Controller();
double PCFreq;
__int64 CounterStart;

[Code] ....

The user should be able to choose which foo the want to use. So I create an object of controller in main like this

Controller* con = new Controller()

Now my issues is, when I take user input (an integer) and try to do this

con->choice1 = choice1;

only the object of con's choice1 is = to user input.

However back at the class for Controller, choice1 hasn't received a value.

I can't initialize through Controllers constructor because I get the user input through a switch statement and the range of con would only be as far as the case.

View 2 Replies View Related

C++ :: Accessing Class Variables In Main

Apr 16, 2014

I am not able to access the class variable noof_vertex in the function merge , the error is the variable is private . below is the code :

#include <iostream>
#include <ctime>
#include <cstdlib>

[Code]....

View 1 Replies View Related

C++ :: Class Member Variables Run Out Of Scope?

Mar 21, 2012

Code:

class CObjects {
int m_CurrentTime;
int m_Steps;
AStarList* OPEN;
AStarList* CLOSED;
std::vector<AStarNode *>solution;

[code]....

CCB is derived from CrowdEntity and in turn is derived from CObjects Inside CObjects, I declared AStarList *OPEN; Why would howmany become garbage (cdcdcdcd) when I reference it in GetBestNode()

View 9 Replies View Related

Visual C++ :: Triangle Class With Member Variables

Apr 8, 2015

C++
Create a Triangle class that has the following member variables:
side1 - a double
side2 - a double
side 3 - a double perimeter area

The class should have the following member functions:

- default constructor that sets the value of all 3 sides of a triangle to 0.0

- a constructor with arguments that accepts values for the three sides of a triangle (member variables) as arguments

- setDimensions - a function that allows the value of the three sides to be entered by the user through the keyboard

- testSides - a function that determines if the 3 values entered can actually be the sides of a triangle. If they do not create a triangle, print the values entered and an appropriate message
--The sum of any two side lengths of a triangle must always be greater than the length of the third side: so side 1 + side 2 > side 3 and side 1 + side 3 > side 2 and side 2 + side 3 > side 1 ( all three must be true for the 3 values to make a triangle)

- getSide1 - a function that returns the value of side 1, getSide2 - a function that returns the value of side 2, getSide3 - a function that returns the value of side 3

- getArea - a function that returns the area of a triangle: The formula for the area of a triangle (when the height is not known) is: A = sqrt (p(p-side1)(p-side2)(p-side3)) where p = (side1+side2+side3)/2

- getPerimeter - a function that returns the perimeter of a triangle: Perimeter = side1 + side2+ Side 3

- A displayTriangleInfo function that displays side1, side2, side3, area, and perimeter for a triangle object.

After testing your code for a single object, create an array of 5 triangles. Use a for loop and the setDimensions function to allow the user to set the values for the 3 sides of a triangle, test the vales entered to determine if the 3 create a triangle. If they do create a triangle than use the getArea and getPerimeter functions to calculate the Area and Perimeter for the triangle and use the displayTriangleInfo function to display all of the data for that triangle. If the three values do not create a triangle then print the 3 numbers entered and an appropriate message. In either case the loop should then move on and get the data for the next triangle from the user.

View 7 Replies View Related

C++ :: Memory Address Of Class Member Variables?

Jun 22, 2013

Suppose I have two classes, MyClassX and MyClassY, each with two member variables, as defined below. I create an object instance of each class, and then create a pointer to each member variable for each object:

Code:
class MyClassX
{
public:
int a;
double b;
MyClassX(int _a, double _b)

[code]....

After converting the hexadecimal to decimal, it appears that with MyClassX, pxb is 8 bytes from pxa, whereas for MyClassY, pya is only 4 bytes from pyb. This makes sense for MyClassY, because the first member variable to be stored is an int, and so will occupy 4 bytes. However, why should this be any different for MyClassX, which also has an int as the first member variable, so shouldn't this also occupy 4bytes?

The reason I have come across this problem is that I am looking into streaming objects to memory and then loading them again. (I know boost can do this, but I am trying it out myself from scratch.) Therefore, this is causing an issue, because I cannot just assume that the size of memory occupied by an object is just the sum of the sizes of its member variables. MyClassX is 8 bytes larger than MyClassY, even though the intuition is that it should only occupy 4 bytes more due to a double being replaced by an int.

View 4 Replies View Related

C++ :: Class Syntax - Variables Are Initialized With Values Between Parentheses?

Mar 1, 2013

Here's a bit of code:

CvClimateInfo::CvClimateInfo() :
m_iDesertPercentChange(0),
m_iJungleLatitude(0),
m_iHillRange(0),
m_iPeakPercent(0),

[Code] ....

does this means that these variables are initialized with the values between parentheses?

View 2 Replies View Related

Visual C++ :: FileSet - Cannot Access Variables From Document Class

Jul 31, 2013

I have written a class "FileSet " in program's Document class.

This class contains other Four classes as

"Machine1" , "Machine2", "Machine 3" and "Machine 4".

Now my problem is Machine 1 can not access variables from Document class or other variables from FileSet.

How to access them ?

View 9 Replies View Related

C++ :: Member Function In Derived Class Call Same Function From Its Base Class?

Sep 18, 2013

How can a member function in my derived class call the same function from its base class?

View 1 Replies View Related

C++ :: Sorting Program That Uses Variables From Another Class - List Not Declared In This Scope

May 13, 2014

I've got this sorting program that uses variables from another class but I'm not sure why its not recognizing it. I'm getting an error length and list not declared in this scope.

#include <iostream>
#include "arrayListType.h"
using namespace std;
template<class elemType>
class orderedArrayListType: public arrayListType<elemType> {

[Code] ....

View 1 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++ :: Unable To Access Private Variables Belonging To Object Class

Nov 21, 2013

I'm unable to access private variables belonging to the object class Date, which my overloaded >> operator is a friend of. I can't see anything in my code that would be causing this error. The .h file and the definition of the problematic overloaded operator from the implementation file are below:

#ifndef DATE_H
#define DATE_H
#include <string>
using namespace std;
class Date {
public:
// Initializes a date to the default value of January 1, 1970.

[Code] .....

The error message states that the vars (month, day, year) are declared as private in the header file and then a reference is made to the lines where I attempt to access these in the .cpp file and it reads: "in this context".

View 5 Replies View Related

C++ :: Read In Lines From A File / Store In Variables Then Construct Instances Of Class

Aug 22, 2013

I can't get my code to compile, i need to read in lines from a file and store them in variables. Then i have to construct instances of my class for how many lines there are in the file and take those variables into them.

I'm getting this error :

"a2.cpp:40: error: cannot convert `Employee' to `Employee*' in assignment"

#include<iostream>
#include<string>
#include<fstream>
void displayInfo();
using namespace std;
class Employee{

[Code] .....

View 1 Replies View Related

C++ :: Passing Variables Into A Function

Mar 29, 2014

ok I have a class Player with lots of variables and im gonna call a function to checkXp, if I call it with the whole player object does it use a lot more memory then if I just passed the couple things I need?

ex
checkXP(Player* play) // this is a whole object of player
or
checkXP(play->getXP(), play->getLVL()) // the variables I want.

I just realized I may not be able to modify anything from player in the checkXP() function

question 1: does passing the whole object use more memory
question 2: if I passed as just the variables I need, I wont be able to modify anything of object play?

View 1 Replies View Related

C/C++ :: Using X And Y Variables In Function Parameters?

Jan 24, 2015

In my program I created three separate return functions. Each function is labeled:

int boxes(int x, int y);
int leftOver(int x, int y);
double avgItemsShipped(int x, int y, int z);

Is it bad programming practice to use 'x' and 'y' in all of my functions? Should I use the this keyword inside the function? We use this often in my Java class and I know it exists in C++, but I haven't actually seen it used (or used it myself yet).

View 3 Replies View Related

C++ :: Declaring Variables In A Function?

Nov 12, 2012

This is a c program that is failing to compile. The error occurs in the calcLabs() function. The error called out is (btw, I'm using VS 2010): Error4error C2143: syntax error : missing ';' before 'type'

I don't understand why the compiler is not letting me declare variables in the calcLabs() function!

Code:
#include<stdio.h>
#include<stdlib.h>
void calcPercent(double *);
double calcLabs();
double calcExams();
double calcFinal();
char calcLetter(float);

[code]...

View 5 Replies View Related

C++ :: Using Pointers Instead Of Reference Variables In Function

Mar 26, 2013

The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program.

int doSomething(int &x, int &y)
{
int temp =x;
x = y * 10;
y = temp * 10;
return x + y;
}

I understand how to covert the reference variables to pointers, however I am stuck on this error. Either I get the error listed in the title or (with a few changes) the error "invalid conversion from 'int' to 'int*'"

What am I doing incorrectly?

#include <iostream>
using namespace std;

int doSomething(int*, int*);

int main(){
int X, Y, result;

[Code] ....

I have multiplied both x and y by 10 and then added them together!

Here is the result " //I really didn't know how else to use the "doSomething" function in a meaningful way. So... I just stated what the function does.

<< result << ".
";
system("PAUSE");
return 0;
}
int doSomthing(int *x, int *y)

[Code] .....

View 1 Replies View Related

C++ :: Returning Two Separate Variables In A Function?

Dec 12, 2013

How to use a function twice to calculate two different variables. How to have a function compute the city tax, then it uses the function a second time to compute the county tax.

My program compiles, and runs fine, however it only outputs the city tax calculation. It seems it never attempts to calculate the county tax.

One thing: All of the directives I used is what we are limited to, no more, no less. He requires a set format and will dock points of you use anything but those directives and void main().

Here is my code so far:

/* function for city tax calculation */

#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
const double city_tax_rate=0.03;

[Code] ....

I am using Visual studio 2010.

View 9 Replies View Related

C :: Functions To Prove Variables Not Changing By Another Function

Jul 8, 2013

It is said that variables in a function cannot be changed by another function. Only by using pointers can variable values be changed. I am writing some functions to try to prove this theory, but I can't get it right.

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
int x = 10;
printf("default x value is %d ",x);

[Code] ......

Code:

#include <stdio.h>
void try1(int x){
printf("x in try1 is %d
", x);
x++;
printf("x in try1 after ++ is %d

[Code]...

View 13 Replies View Related







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