C++ :: Filling Vectors With Pointers To Account Objects

Jul 27, 2013

So I'm trying to fill a vector with pointers to account objects.

std::vector<account*> fill_vector() {
std::vector<account*> temp;
std::ifstream s;
std::string str;
s.open("H://account2.dat");

[Code] ....

The accounts have four different types and I am supposed to skip over ones that have an invalid account type and throw an exception:

account* factory(std::string account_code, std::string first_name,
std::string last_name, char type, double balance) {
try {
if(type == 'A') {
simple_account *a = new simple_account(account_code, first_name, last_name, balance);

[Code] .....

My problem is they program will not skip over my rejected accounts.. still adds them to the vector but I cant figure out why!

View 8 Replies


ADVERTISEMENT

C++ :: Creating / Filling And Deleting Dynamically Allocated Array Of Objects

Jul 26, 2012

Project compile successfully but console turn off with "Windows " with error doesn't print or get anything

Code:
#ifndef Point_HPP // anti multiply including gates
#define Point_HPP
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>

[Code] .....

View 2 Replies View Related

C++ :: Deposit Vectors With Different Objects?

Nov 6, 2013

I my code i have a base struct ...

Then others structs made ...

struct base{};
struct a1 : base {
int a;
int b;

[Code] ....

Now i must deposit all these containers(maybe & of containers) in another vector...

How i can do that? Can i write

vector<vector<base*> > all;
all.push_back(&v1);
all.push_back(&v2);

View 14 Replies View Related

C++ :: Manipulating Set Of Containers - Vector Of Vectors Of Objects

Mar 5, 2013

I need manipulating a set of containers. I created a vector that contained vectors of objects:

std::vector< std::vector<Terrain> > mapArray(num1, std::vector<Terrain>(num2));

where num1 and num2 are arbitrary numbers. and Terrain is the class of objects I'm trying to store.

I want to be able to use push_back on both the main vector and the vectors within the mapArray vector but I'm unsure of how to target the inner vectors with push_back. How to dynamically store a 2D array of objects.

View 10 Replies View Related

C++ :: Assignment Of Objects To Pointers

Jun 6, 2013

I am using OpenCV to read and manipulate a set of images, which I need to store in an array to work with them. Here is a snippet of the code:


#define MAX_IMAGES 8
typedef Mat* MatPtr;
int main(int argc, char** argv) {
char imageName[] = "./res/imageX.tiff";
MatPtr datacube[MAX_IMAGES];

[code].....

I have an array of pointers to Mat objects (an OpenCV class used to hold info and data about an image), which I will use to store the images. The function imread reads an image and returns a Mat object loaded with the relevant data about the image.However, this gives me a nice segfault when the assignment takes place. Of course, I can swap it with the following code, but since I'm working with big images (2048x2048 and upwards), it's really inefficient:

for(unsigned int i = 0; i < MAX_IMAGES; i++) {
imageName[11] = 49 + i;
datacube[i] = new Mat(imread(imageName, -1));
}

Is there any way to do this elegantly and without much hassle?Again, excuse my rustiness and anything completely stupid I might have said. It's been a long time since I worked with C++. Managed to circumvent the problem by using a STD vector instead of an array. I'd still like to know the answer to this riddle...

View 6 Replies View Related

C++ :: Using Array Of Pointers To Objects?

Sep 27, 2013

I've created an Array of pointers to objects using:

Person ** A = new person * [arraysize];

When I intend to access a specific person do I have to do this? :

something = A->[i];

and when I want a specific object within my struct do I have to do this? :

something_else = A->[i]->random_int;

View 10 Replies View Related

C++ :: Array Of Pointers To Objects?

Dec 5, 2013

my code:

int OKCount=0;
int WaitingCount=0;
int ReservationCount=0;
Flight::Flight(int capacity, int waitingMax) {
seats=capacity;

[code].....

reservations is a data member in the class flight as:

Reservation **reservations;

OKReservation is a derived class and its abstract base class is Reservation.

My problem is that the reservations array loses its value in other function

View 8 Replies View Related

C/C++ :: How To Add Objects To A List Of Pointers

Apr 14, 2014

I have a data structure defined up here called this:

typedef list <classSpec*> ClassSpecList;

I'm trying to add stuff into the list here based on functions that return certain values of that match the same data type. In one function, I have a list pointer object defined here and I have another statement that calls a function.

ClassSpecList *answer = 0;
classSpec *thisanswer = parseClass(br);

Basically I'm trying to add the results of what thisanswer returns into my main ClassSpecList. Problem is, when I try

answer->push_back(new classSpec (*thisanswer));

It compiles but I get a seg fault

When I try somethign else like:

answer->insert(ClassSpecList.begin(), *thisanswer);

I keep getting primary expression errors and I do not know why. I even tried it with other list made without typedef and I still get those.

View 6 Replies View Related

C++ :: Sort Vector Of Pointers To Objects

Nov 5, 2014

Im creating a program for a race. The Race class has a vector of results and each element of that vector is a pointer to a result. The Result class has a Time and a pointer to a Participant. So in each race there are various results and it is a result for each participant.The Time is a class that has hours, minutes and seconds. How can I sort the vector of results from the result of the participant with the fastest time to the result of the participant with the slowest time?My code is like this:

//.h file:
class Time {
unsigned int hours;
unsigned int minutes;
unsigned int seconds;

[code]....

What am I missing to get my code to work?

View 9 Replies View Related

C/C++ :: Sort Vector Of Pointers To Objects?

Nov 5, 2014

Im creating a program for a race. The Race class has a vector of results and each element of that vector is a pointer to a result. The Result class has a Time and a pointer to a Participant. So in each race there are various results and it is a result for each participant. The Time is a class that has hours, minutes and seconds. How can I sort the vector of results from the result of the participant with the fastest time to the result of the participant with the slowest time?

Im getting some errors in my code. I put the error as comments in the code. Each error is after the line where it occurs. My code is like this:

//.h file:
class Time
{
unsigned int hours;

[Code]....

View 8 Replies View Related

C++ :: Hold Vector Of Pointers In Same Class As Instances Of Those Objects?

Feb 10, 2015

Using SFML, I had a Board class which held multiple vectors of all of my object types in the game, and then it also held a vector of pointers to the memory addresses of these object instances, like this

class Board{
//...
std::vector<AbstractObject*> GetAllLevelObjects(){ return allLevelObjects; }
//so these are used to hold my object instances for each level

[Code]....

When looping through this vector and drawing the sprites of the objects, I get the runtime error 0xC0000005: Access violation reading location 0x00277000. I solved this error by storing the vector of pointers in the class that holds my Board instance, but I'm wondering why only this solution worked? Why couldn't I just have my vector of pointers in the same class that the instances of those objects were in?

View 2 Replies View Related

C++ :: Transfer Ownerships Between Objects (passing Arguments) Using Raw Pointers?

Sep 4, 2012

Code:
void Class1::Func(shared_ptr<type1> parameter)
{
}
or
void Class1::Func(const shared_ptr<type1>& parameter)
{
}
or
Should I ever pass arguments/parameters to other objects using shared_ptr's or raw pointers?

View 3 Replies View Related

C++ :: Vector Of Pointers - Push Back Objects / Constant Parameters

Apr 11, 2014

I have a class called Question:

#include <string>
#include <vector>
using namespace std;
class Question {
string title;
vector<Thing*> posAns;
vector<Thing*> negAns;

[Code] ....

error: no instance of overloaded function 'std::vector::push_back()' matches the arguments list
argument types are (const Thing *)
object type is: std:: vector<Thing *, std::allocator<Thing *>>

So it cannot be constant, what if I just leave it non-constant? Will it be safe?

View 2 Replies View Related

C++ :: Creating Array Of Pointers To Base Class To Point To Derived Class Objects Dynamically

Jan 16, 2013

Please consider the following code :

#include <iostream>
using namespace std;
class superclass;
class subclass1;
class subclass2;

[Code] ....

As you can see I want to create a dynamically allocated storage of references to a parent class each of which can then point to a child class, how ever I do not know how to extract the child class out again from that array so i may access its variable b.

View 2 Replies View Related

C++ :: List Of Vectors (vector Of N Vectors Of M Elements)

Mar 19, 2014

I create a list of vectors (a vector of n vectors of m elements).

std::vector <std::vector <int> > vsFA (n, std::vector<int>(n));

How I assign values? I try below, but not worked

void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA
{ vsFA[n] [m]= simTime().dbl();
OR
vsFA[n].push_back(simTime().dbl());
}

View 1 Replies View Related

C++ :: Create Two Vectors And Then Loop Through The Vectors

Sep 19, 2014

This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.

The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.

So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:

[1,1]
[1,2]
.
.
.
[10,10]

This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.

View 1 Replies View Related

C :: This Account ID Does Not Exist - Segmentation Fault

Apr 11, 2013

It is suppose to display the message "This Account ID does not exist" but why do I get "segmentation fault"??I was able to compile and run the program so it shouldn't be a problem of the compiler.

Code:

#include <stdio.h>#include <string.h>
struct Account {
char* Account_ID;
char* Account_Type;
char* AccountOwner_FirstName;
char* AccountOwner_LastName;
float* Balance;

[Code]....

View 11 Replies View Related

C++ :: How To Account For A Size 0 Vector In Function

Dec 16, 2013

I'm trying to do is write a program that fits to a separate test program. The test program provides different size vectors that my function should try and binary search. If the element is found, the function should return 1, and if the element is not found, it returns -1.

Here is the code:

int binSearch(const vector<double> & data, int elem, int & comps) { {
int beg=data[0];
int end=data[data.size()-1];
int mid=(end+beg)/2;

[Code] ......

The problem is that one of the vectors my function is supposed to binary search is a vector of size 0. I tried to throw in an if statement that would return -1 if the size was == 0, but then the program never fully completed and just kept running. So, how can I account for a size 0 vector in my function?

View 2 Replies View Related

C++ :: How To Take Into Account White Spaces In A String

Apr 21, 2013

as i am doing an encryption program on a playfair cipher. I am now stuck on a problem on decryption.If my string is helloworld (without a space), it will decrypt normally.However , if my string has a space in between it. Let`s say Hello World, it will not decrypt normally.How do i take into account the space that is in between hello & world?

example: hello world

View 4 Replies View Related

C# :: Create Account And Login To Windows?

Mar 18, 2014

I want to create user account and login to windows. I have to read username from DB and create window user for login to window. So,Can I create windows account and login to windows with C#

View 8 Replies View Related

C :: How To Account For Different Number Of Chars In Array Of Names

Dec 9, 2013

I am trying to make a for loop that will print out chars in an array while using a #define before main. My problem is that each name has a different amount of chars in it. How do you account for that when you are trying to define a size? For example, I am playing around with the numbers and I just put 7 in for size:

Code:
#include <stdio.h>
#define sizeOf 7
//char personName( char * name[] );
char printName ( char * name[]);

[Code] .....

View 8 Replies View Related

C/C++ :: Calculating Interest Earned On Bank-account

Oct 21, 2014

This exercise should familiarise you with loops, if-then-else statements, and recursion. You will have to design and implement a program that calculates the interest earned on a bank-account. Deadline is the end of Tuesday in week 4.

Interests are compounded; that is, you earn interest on interest. Given a yearly interest rate of say, 6%, you can calculate the total sum available when an initial sum of 4000 pounds is put away for 13 years as follows:

4000 * ( (1 + [6/100])^13 ) = 8531.71 pounds

where the caret symbol denotes 'to the power of'. One way to calculate the power is by repeatedly mulitplying. Ie, you can mulitply 1.06 with 1.06 12 times to calculate 1.06^13.

PART 1

Design and implement a function that raises X to the power Y for a real number X and a positive integer Y. The function must use a while loop.

Design and implement a main program that calculates the sum availble when 1000 pounds has been put away for 25 years with 5 percent interest.

Change the while-loop in the function to a for-loop.

View 12 Replies View Related

Visual C++ :: Building A Savings Account Program?

Mar 12, 2014

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

[Code].....

I need to modify the program to use annual interests rates of 3%, 4%, and 5%.

After that I need to modify the program to make it so the user enters the dollar amount of the deposit, the interest rate or rates, and the number of years.

I'm a design student at New England Tech but before we can go full design they want to make sure we know for sure if we want to be a designer or a programmer and so we need to take C++ classes

View 4 Replies View Related

Visual C++ :: How To Tell If User Account Is Set Up With Roaming Profile

Nov 22, 2013

Is there a way to know from a Windows service application (running as a local-system) if a specific logged in interactive user account is configured with a roaming profile? I need this to be compatible with Windows XP SP3.

View 9 Replies View Related

C++ :: Mini Bank Account System - Using Header Files?

Feb 13, 2013

i am currently doing a mini bank account system using visual studio...i need using the header files...the question requires to use 3 header files for each class.these are the classes:

a)Accounts
b)CurrentAccounts
c)SavingAccounts

i have done the first part... how to do a new class in a different header file..

View 3 Replies View Related

C++ :: Bank Account - Base Class Undefined Error

Apr 20, 2014

I have an odd compiling error. My base class is all delcared and read to go. But I could not figure out how to get my sub classes inherit from it. So I had to make everything public. Even inheriting using the protected inheritance thingy, still could not get them to inherit from that base class.

So I compiled the program, and no other class came back with an error. only my base class. Here is the base class:

#include <iostream>
#include <string>
using namespace std;
class Bankaccount {

[Code] .....

The error I'm getting is saying:

error C2143: syntax error : missing ';' before 'using'
Where is there anything needing a semicolon before using?

'Bankaccount' : 'class' type redefinition
see declaration of 'Bankaccount'

Is it saying this because I don't have any private class members?

'Bankaccount' : base class undefined

But it is defined.

What is the issue with this class? And how can I get it to compile and run?

View 10 Replies View Related







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