C++ :: A Call To A String Names In A Class Not Display

Apr 19, 2014

I created class called students which suppose to store students names of any sizes in an arrey but when I call the display function it does not show the names.

#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;
class students{
public:
string names[SIZE];

[Code] ......

View 1 Replies


ADVERTISEMENT

C/C++ :: Call To String Function To Display Names In Class Not Display

Apr 19, 2014

I created class called students which suppose to store students names of in array but when I call the display function it display only the first name. but I want it to display names depending on the array size.

#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;

[Code]....

View 3 Replies View Related

C++ :: Call Only Those Functions Whose Names Are Written In Disk File

May 26, 2013

Here is a working C++ program and its output that reads the names of a certain number of functions whose names are written in a disk file that provides the control parameters in a near-real time fashion. Based on this information, the program calls those functions whose names were given in this text file as parameters. The method I have used is to build a map of functions that connects the names of the functions to the actual functions. Once this map is created, then it is very easy to iterate in such a way that only those selected functions are called.

So far this is working well, and it makes the logic of the code easier because ultimately there will be a large inventory of functions (probably hundreds of functions), and this way of pre-building a map of functions avoids writing hundreds of if statements in the code. Of course, pre-building this reusable map in the background is still equivalent to writing that many if statements, but at least it makes the code very compact and much more automatic, since it is done only once.

But I now have a related question: In this case (when the selected subset of functions to call is given as incoming data as in this example), does C++ make it possible to avoid using maps of functions, by directly applying the string variable that holds the name of the function in order to call the original function immediately For instance, if a string variable s = "MyFunction", then is there a more direct way of using this string as if it were the actual function whose name is spelled exactly in that way? This would make the code even more compact.

Here is the sample test code for the map of functions, and its output:

First of all here is the text file "FileForNamesOfFunctions.TXT" that contains the part of the "data", which is the set of functions select from from the inventory and only call these:

Code:
function2
function3
function5 And here is the C++ code that uses this "data":

Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

[Code] ....

View 8 Replies View Related

C :: Display The Names In A Queue

Mar 12, 2014

I have an assignment that needs to display the names of customers to be served according to a sequence. coding to display the names accordingly?

Code:

#include <stdio.h>
#include <stdlib.h>
#define MAXIMUM 20
void create();

[Code].....

This is my output. I have trouble displaying the names of the customers as it outputs null when I try to display my position in queue.

View 4 Replies View Related

C/C++ :: Display Names In A Queue?

Mar 13, 2014

I have encountered errors when trying to display the customers' names in a priority queue.

#include <stdio.h>
#include <stdlib.h>
#define MAXIMUM 20
void create();
void priority_insert(int data);
void check(int data);

[code]....

I have gotten the following output:

Peter
Peter
<Null>

How do I correct my coding to display like below:

John
Peter

View 1 Replies View Related

C++ :: How To Add A Call Function After Main Display Loop

Apr 29, 2013

How to ADD a call to the FindMostExpensive function AFTER the main display loop, and use the index returned to display the information about the most expensive car?

// Session7.cpp : Defines the entry point for the console application.
//using struct
// reading from file
// using functions

#include "stdafx.h"
#include <iostream>
#include <iomanip> // only used to tidy up the console output here
#include <fstream> // added file handling

[Code] .....

View 1 Replies View Related

Visual C++ :: Display Arrays Using Call Statements

Oct 21, 2014

I am trying to display the following arrays.

int a[4]={5,9,2,10}
int b[3][3]={1,2,3,4,5,6,7,8,9}
int c[2][3][2]={1,2,3,4,5,6,7,8,9,10,11,12}

Using these call statements

Display (a,4);
Display(b,3);
Display(c,2);

I'm not sure on how to put this all together but this is what I have so far.

Code:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
} int a[4] = {5,9,2,10};
Display(a, 4);

[Code] .....

View 4 Replies View Related

C++ :: Can Base Class Call Overridden Function From Derived Class?

Aug 28, 2013

I just wondering if a base class can call the overridden function from a Derived class?

Here's an example:

//Base Class H
class BaseClass {
public:
BaseClass();
virtual ~BaseClass();
virtual void functionA();

[Code] ....

So basically, when I am creating a new object of Derived class, it will initialize BaseClass and the BaseClass will call functionA but I want it to call the function overridden by Derived class.

I know that if I call newObj->functionA it will call the overridden function. Right now I want the base class to call the overridden function "this->functionA(); in BaseClass" during its initialization. Is it possible to do that?

View 9 Replies View Related

C++ :: How To Call Function From Derived Class In Base Class

Dec 24, 2013

Basically, I have a base class called MainShop and it has 3 derived classes which are SwordShop, SpellBookShop and BowShop. I want the base class to be able to call a function from one of the derived classes but no matter what i do, it doesn't seem to work!

Here is my code:

#include "MainShop.h"
//BaseClass cpp
void MainShop::EnterShop(Hero& hero)

[Code]....

I have two other derived classes, but its basically the same concept. I have a function in one of the derived classes and i would like to call it from the base class. This is one my derived classes:

//SwordShop derived cpp
#include "SwordShop.h"
void SwordShop::soldierShop(Hero& hero)
{
/* some code here*/
}

View 4 Replies View Related

C :: CLASS Keyword In Function Names

Sep 24, 2014

I'm trying to read a C code, but there are functions including CLASS word at the titles of functions. Is it a correct implementation?

For example: double CLASS getreal (int type)

What is the meaning of CLASS in titles of functions in C? I could not find such an usage in my C book?

View 6 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++ :: Splitting First And Last Names From String

Jan 15, 2013

The following code shows bad memory access error (segmentation fault) when I run it. It does this right after it asks for name and the user has entered it.

#include <iostream>
#include <sstream>
using namespace std;
struct Name {
string first;
string last;

[Code] ....

View 4 Replies View Related

C++ :: Call From Class Created Inside A Class

May 21, 2014

I have 2 Classes.
-> StateManager
-> Intro

The StateManager creates the Intro. I want that the Intro calls a function of the StateManager if finished. How can I achieve that?

At line 24 at the Intro class you can see what I tried.

StateManager:

#pragma once

#include "State.h"
#include "Intro.h"
class StateManager{
private:
std::vector <State*> States;

[Code] .....

View 5 Replies View Related

C++ ::  program That Reads Into String Object A Name With Three Blanks Between First And Last Names

Oct 4, 2014

" Write a program that reads into a string object a name with three blanks between the first and last names. Then extract the first and last names and store them in separate string objects. Write a function subprogram that displays its string argument two times. Call this function display the first name for times and then to display the last name six times."

I completed coding the first part of this task with the strings and combining strings together. However, i have having trouble with the other half of this task. It begins from "Write a function subprogram to display the last name six times." This is where i have so far --

#include <iostream>
#include <string>
using namespace std;
int main()
{
// Defining the strings

string firstname, lastname;
string wholename;
string greet = " Hi ";

[code]....

View 2 Replies View Related

C++ :: Program To Read Middle Names Within Text File - Full String Not Appearing

Oct 24, 2014

I've a problem here...

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])

[Code] ....

The program needs to be able to read the middle names within the text file named Info2.txt

Simply adding the Mname or any related value where the other to name values doesn't do anything and only the 1st line appears on the output.

Don Jon111012
Jack Bo Todd151015
Jill Jo Jane161011
Bob Jack Chuck 131513
Da Fu111012

That is the correct way it appears in the text file. Also I know it's commented out, but that just to keep the program from crashing.

current output

Survey Results:

Name Results
Don Jon 33.00

This is the Info1.txt file info by the way.

Ken A202017
Gus B151015
Bill C151512
Jara C151720
Lu E101510
Chow B171015

And the output

Survey Results:

Name Results
Ken A 57.00
Gus B40.00
Bill C42.00
Jara C52.00
Lu E35.00
Chow B 42.00

Which when ran with Info1 selected, it is the correct output I'm looking for. I've tried getline and other solutions and they didn't work.

View 1 Replies View Related

C++ :: Convert Passed String Into Proper Alpha Case And Sort Array Of Names

Apr 25, 2013

I want to create 2 functions to (1) convert a passed string into proper case (capitalize the first alpha character of a string and every alpha character that follows a non-alpha character); (2) sort the array of names (after it has been converted to proper case).

I tried these two:

console.writeline (lower.toUpper());
void bubblesort (string array[],int length);

but I don't know if they are good.

View 2 Replies View Related

C++ :: Delete Specified Names From A List Of Store Names?

Feb 10, 2013

i have a vector of stores. i would like to delete the specified choice(store) from the list. Here is what i have but my erase statement is wrong and wont compile.

void Store::deleteSpecifiedStoreFromList(string choice) {
for (int i = 0; i < this->stores.size(); i++) {
if(this->stores[i].getStoreNames() == choice) {
this->stores.erase( std::remove_if( this->stores.begin(), this->stores.end(), choice ), this->stores.end() );
}
}
}

View 4 Replies View Related

C++ :: How To Call Methods Of Class

Feb 27, 2014

how to call the methods of the class.I have an object call v which is an array and I don't how to call the methods of the class. The error is here:

v.readDates(v[a]);

#include "Date.h"
#include <iostream>
using namespace std;
int main(){
int a;
cout << " HOW MANY DATES DO YOU HAVE? " << endl;

[code]....

View 3 Replies View Related

C/C++ :: Input Call By Value In Second Class

Feb 1, 2015

I am trying to input a call by value in the second class. It will not compile with how it is currently and says that the pounds needs to be a different variable. Why is this? Is this close to a call-by-value or am I way off?

#include <iostream>;
using namespace std;
int main() {
int a, b, c, d;
cout << "Please enter your weight in Pounds and Ounces ";

[Code] .....

View 2 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++ :: How Do API Call Back To Class Members

Jun 24, 2014

I've been creating an API and I'm now stuck on callbacks. There are many APIs that allow callbacks to class members(e.g. Windows API) using a void pointer to the object. I've searched the internet for hours and I can't find one example of how to use the "hidden object parameter" of an class method pointer that doesn't use std::function/bind or boost::function/bind. Any information on how API's like Windows API are able to use class methods as callbacks

View 6 Replies View Related

C++ :: No Matching Function For Call To Class

Nov 4, 2014

I'm having this pain in the ass error (No matching function for call to Data::Data() ) on this block of code:

Etapa::Etapa(string nm, float dist, string loc, Data dt) {
nome = nm;
distancia = dist;
local = loc;
data = dt;
}

[Code].....

I guess this is happening because I'm trying to give Etapa an argument of Data type and I can't do it or put it in a variable since it has 3 parameteres (mes, dia, ano).

View 2 Replies View Related

C++ :: Compiler Will Not Allow To Call A Public Method In Another Class

Feb 23, 2013

I have read the book over and over and I thought I understand "CLASS". But when I applied it and write the code the compiler tells me that there is a compiling error.

1. I have this method addProduct(Product* pProduct) in a Class called ProductRack, the code is in ProductRack.cpp file. The declaration of the Class methods and private variables are in ProductRack.h header file.

2. But when I call a method in the DeliveryCHute Class from the ProductRack Class I get a compiler errors which are these:

A.IntelliSense: a nonstatic member reference must be relative to a specific object
B.error C2352: 'Project1::DeliveryChute::insertProduct' : illegal call of non-static member function

And this is causing the error:

if (Project1::DeliveryChute::insertProduct(pProduct) == false)

//THIS IS JUST ONE METHOD INSIDE ProductRack.cpp
bool
Project1::ProductRack::addProduct(Product* pProduct) {
// Todo : Implementing
if (Project1::DeliveryChute::insertProduct(pProduct) == false)
return true;

[Code] .....

View 5 Replies View Related

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/C++ :: How To Call Member Functions With Template Based Class

Sep 27, 2014

This week we are learning to use templates, and I don't understand how to call my member functions with my template based class. I tried the standard convention of calling member functions, but I keep getting an error saying name following"::" must be a class or namespace name. I'm thinking my problem lies with my typename T, but I am unsure. Line 16 is where I am getting tripped up.

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
template<class T>
T Set
{
public:

[Code]...

View 2 Replies View Related

C :: Return A String To Then Call It On Main Function?

May 26, 2013

I'm trying to return a string to then call it on main function.

Code:
const char* coiso(int chave){
char str [50];
sprintf(str,"%d",chave);
char txt[50] = ".txt";
strcat(str,txt);
return str;
}
int main () {
const char* info = coiso(8);
printf("%s",info);
}

If I do a printf("%s",str) in coiso function it works but the following code doesn't work.

View 10 Replies View Related







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