C/C++ :: Access The Swapping Function?
Nov 22, 2014
Giving the following program, how do i access the swapping function. I've tried swapp::change <int> ( a, b ) ; and it gave me 4 errors. Here's the code:
#include <iostream>
using namespace std;
template <typename T>
class swapp
[Code].....
View 5 Replies
ADVERTISEMENT
Feb 15, 2015
I have a question about one function in my program. Write a function that will replace players in a tim. New player gets in the game, and takes the place of one that leaves. Prototype of function is:
Code:
void replace(TEAM *p,PLAYER newplayer,int num)
where second parameter is new player, and the third is a jersey number of player who leaves the game.Two structures are defined as:
Code:
typedef struct{ char name[25],surname[25];int number;}PLAYER;typedef struct{ char nameofteam[25];int numberofplayers;PLAYER *players;}TEAM;
First I tried to read which player should get out, but that didnt work:
Code:
printf("which player should get out?
"); do { scanf("%s",p->players.number) } while(p->players.number);//
Choose one of previously read players Second thing is to read a new player and replace him with the chosen who leaves.
View 2 Replies
View Related
Feb 14, 2015
I have a question about one function in my program. Write a function that will replace players in a team. New player gets in the game, and takes the place of one that leaves. Prototype of function is:
void replace(TEAM *p,PLAYER newplayer,int num)
where second parameter is new player, and the third is a jersey number of player who leaves the game.
Two structures are defined as:
typedef struct {
char name[25],surname[25];int number;
}PLAYER;
typedef struct {
char nameofteam[25];int numberofplayers;PLAYER *players;
}TEAM;
First I tried to read which player should get out, but that didnt work:
printf("which player should get out?");
do {
scanf("%s",p->players.number)
} while(p->players.number);//Choose one of previously read players
Second thing is to read a new player and replace him with the chosen who leaves.
View 3 Replies
View Related
Jan 4, 2015
Write a program using user-defined function which is passed a string and that function should cycle the string.(Do not use any string related functions). E.g.
If the string is : Chetna then it should print as Chetna, hetnaC, etnaCh, tnaChe,naChet, aChetn
Ans.
#include <iostream>
using namespace std;
char swamp(char a[], int x) {
for(int k=0; k<=x; k++) {
char l= a[x]; a[x]= a[0]; char p=a[x-1]; a[x-1]=l;
for(int i=1; i<x-2; i++) {
[Code]...
View 19 Replies
View Related
Jun 15, 2013
I have a pointer to a pointer to a C string:
char**objectData;
In this string there are some numbers with a dash between them, for example, "5-10". I need to read these numbers in and then increment them. So "5-10" becomes "6-11", "6-11" becomes "7-12", etc.
So far I have:
Code: char temp[350]; //350 chars is plenty enough
// Copy the first characters BEFORE the numbers into a new char array. The next characters are the numbers.
strncpy(temp, *objectData, 39); The next steps are:
- Extract the two numbers from the C string (determining if the number is 0,2 or 3 digits long) and write them into two ints. I'm stuck here.
- Increment the ints
- Write the ints into the array with a dash inbetween.
View 6 Replies
View Related
Nov 25, 2014
I thought I'm done doing mg activity, but my professor said that we need to use a Temporary Variable for Swapping but where to put it.
Here is his activity:
Activity: Swapping Create a program that accepts a 10-element array of type int. Where the 1st user-input is stored in the 1st element of the array; the 2nd user-input is stored in the 2nd element of the array; so on so forth until the last user-input stored in the last element of the array. Your source code should be able to SWAP the values of the 1st and 10th; 2nd and 9th; 3rd and 8th; 4th and 7th; and 5th and 6th elements. It should display the values of the original and the swapped values of the array. example:
Enter 10 integer values:
array[0] = 1
array[1] = 2
array[2] = 3
array[3] = 4
[Code]....
View 1 Replies
View Related
May 3, 2013
I have a function that is suppose to swap positions of 2 letters but It doesn't seem to work. Im passing in the array of char into the function.
void swapletter(char word[]) {
char temp1;
int swap1;
int swap2;
cout<<"What is the first location: ";
cin>>swap1;
[Code] ....
View 6 Replies
View Related
Aug 11, 2014
I've written a simple class given below. I had set the values through setab() function but the add()function didn't work.
Compiler shows CPP/class.cpp|20|error: ‘int Calc::add()’ is private|
#include <iostream>
using namespace std;
class Calc
[Code]....
View 5 Replies
View Related
Nov 24, 2014
I am essentially trying to get a value from a 'Matrix' that is created. Using a function in the class where the matrix is created. But when trying to do this I get the error: Call to non-static member function without an object argument in this line when trying to call the function:
Matrix::get(sizeR, sizeC);
View 6 Replies
View Related
Apr 9, 2013
I tried normal swapping method like this (counter is number of structures written in file) :
Code:
fopen("books.txt","r+");
system ("cls");
for(i=1;i<counter-1;i++){
for(j=1+1;j<counter;j++){
fscanf(f," %[^,], %[^,], %[^,],
[Code] ....
But it doesn't do anything.
View 2 Replies
View Related
Jul 29, 2014
So basically, I started out with each wizard == 1 winform, but then I found another way to do it by making the content of each wizard step a user control, then say, on initial deployment, it load usercontrol1, then when i click next, the panel hide usercontrol1 for usercontrol2 and so forth. Would it be feasible to create all usercontrols (all the wizard step) and add them in an array, then i can load them by index?
View 7 Replies
View Related
Oct 24, 2013
Write a program that gets a sequence of unsigned integers.the user can enter at most 100 integers.
After getting the numbers, the program allows the user to repeatedly choose one of the three options:
1. swap the location of two entries in the sequence. if this option is chosen the user is prompted to enter the two locations to be swapped.
2. print out the sequence.
3. repeatedly swap two locations in the sequence until getting back to the state before this operation started. then print out the number of swaps performed.
View 3 Replies
View Related
Oct 22, 2014
I am working on a program where I sort elements into alphabetical order and then when one is less than the other I swap them. I first did it by swapping the data but they want me to swap the nodes instead and I am having trouble doing that.
Node *add_node( Node *list, const string &s ) {
struct Node *n = new struct Node;
n->word = s; // copy string s to word
n->next = 0;
// add node n to the list
// the list should always be in ascending alphabetical order
n->next = list;
list = n;
[Code] ....
View 2 Replies
View Related
Nov 15, 2014
I've been working on this linked list priority queue . I know that the root of the problem is in my swapUp() function (swapping the positioning of two nodes based on their priority), because the list works great up until it is called. The seg fault is not actually being caused by swapUp(), it's being caused by peekAt(), which returns the element in the node at position n. But the error does not occur unless swapUp() is called first, so that is where the issue is (I think).
There is also a seg fault being caused in the destructor, which I believe may have the same root cause in swapUp().
PRIORITY QUEUE:
#ifndef JMF_PriorityQueue
#define JMF_PriorityQueue
#include <iostream>
#include <string>
template <typename T>
class PriorityQueue{
[Code] .....
Okay, so I've tried implementing SwapUp() in a different new way, but it's still giving me the same problem
template <typename T>
void PriorityQueue<T>::swapUp(Node * target){
Node * partner = target->next; //Partner = target next
[Code] .....
This is such an elementary logic problem I don't know why I'm having so much trouble with it.
View 4 Replies
View Related
Dec 1, 2014
Let's say there is a document which stores data of exams of 3 subject. The document is in the below format:
Subject code [spc] Student code [spc] Exam score [endl]
Repeatedly, there are 100 data. E.g.
ENGL_S12 [spc] 000001 [spc] 90.5
ENGL_S12 [spc] 000005 [spc] 77.3
MATH_G22 [spc] 000502 [spc] 100
LATI_F11 [spc] 002005 [spc] 65.4
...
Now I have to write a function show_exam_descending(Data d, string subCode)
when I call show_exam_descending(d, "ENGL_S12")
the program will execute to show all the students' exam scores in ENGL_S12 in DESCENDING order...
For this to run, I have declared a struct Data:
struct Data {
string subjectCode;
int studentCode;
double examScore;
);
For the search, I have written a function before to load all the data from the document by using pointer and dynamic arrays. It works so well. What troubles me is the way to swap the elements (i.e. examScore) of different students in struct dynamic arrays. I am able to display all of them, but don't know how to swap.
View 8 Replies
View Related
Jan 21, 2015
Am trying to write table object into file. Here's the source code
.hpp file
class Table {
private:
int table_no;
std::string table_type;
bool engaged;
std::time_t start_time;
double total_sec;
[Code] ....
When i compile the above code i get the following error...
table.hpp: In function ‘std::ifstream& operator>>(std::ifstream&, Table&)’:
table.hpp:19:7: error: ‘int Table::table_no’ is private
table.cpp:91:12: error: within this context
table.hpp:20:15: error: ‘std::string Table::table_type’ is private
table.cpp:92:12: error: within this context ...........
View 4 Replies
View Related
Sep 9, 2013
if we don't provide the acces modifiers for base class and we need to manipulate the private data of base class in derived class. Is there anyway to acces the private data members? Here's a coding example
class A {
private :
int a;
};
class B : public class A {
public :
void displayA() { cout<<a<<endl; }
};
how i can acces the a of base class A in derived class B without acces modifiers.
View 16 Replies
View Related
Dec 16, 2012
In my MFC, CMyPorpertyPageDlg is derived from CPropertyPage. How to access its member function from a nonmember function in the same CPP file?.
void Non_Member_Get_PorpertyPage()
{
CMyPorpertyPageDlg* pPageDlg = ....
}
View 4 Replies
View Related
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
Mar 30, 2013
I want to have it so that when i ask for the person witch item they want to drop on the ground it goes into another vector that i can pick back up the item if they want it back and erase when they walk away.
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
struct InventoryItem
[Code] ....
View 4 Replies
View Related
Jul 17, 2014
Code:
#include <iostream>
using namespace std;
void f();
extern int x;
int main() {
[Code] .....
x is declared outside the functions and defined inside main(). Then why this code produces a compile error?
x is already declared so it can be used in f(); and when I call f(), x is already defined. Then why can't f() sets the value of x (in main) to 10?
View 3 Replies
View Related
Apr 9, 2012
this is the XML document i have:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<ConfigParams>
<Param Name="1">1857</Param>
<Param Name="2">10.31.225.163</Param>
[Code] ....
How to write a C++ code to access thing. (like we use JAXB in java)
View 1 Replies
View Related
Jun 29, 2014
Is it possible to access file properties from c++ program? For example, user could drag file to program and then it displays a detailed information about file like date modified, size, type and etc..
View 1 Replies
View Related
Sep 8, 2014
How to access the name and file name members on line 42 and 43?
Code:
typedef struct {
char * name;
char * filename;
} FILES;
FILES * files[256];
}
[code]...
How to access the name and filename from within function?
*files[count].name = chTmp;
View 9 Replies
View Related
Jul 31, 2013
I have an array called abee1.
int abee1[4][3];
I have done some string function (like: "abee" + "1" ) and have "abee1" as string which is the same as abee1. How can I copy the data of abee1 into another array with same size, for example abeeTwo[4][3], using only the name of abbe1 as string ("abee1") not by abee1 directly.
View 4 Replies
View Related
Jun 25, 2013
I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.
std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;
[Code] ....
View 2 Replies
View Related