C++ :: Repeated Handling With Different Methods Calls But Same Parameters

Apr 24, 2014

I have several functions doing similar things, inside their implementations, the parameters are the same, but they call different methods.

I want to create one function to make the structure easier, and reduce the duplication. I heard template might be one solution. But I am not sure how to use it in this case.

void GetA(...XXX) {
for()
{

[Code].....

View 1 Replies


ADVERTISEMENT

C# :: DB Calls Via Tasks?

Jan 6, 2015

I have a multi-thred piece of code that should be fast. As I have to update a Database from time to time, I wonder if I do it in a prpoer manner with calls like this:

Task.Factory.StartNew(()=>update_execution_to_db(exec));

Those are my sporadic updates, my ongoing update have a queue and a dispatcher thread reading from the Q, I just don't want to use this overhead for the sporadic updates.

View 6 Replies View Related

C++ :: Calls From Ancestor

Mar 7, 2012

Code:
class A {
virtual method1() { };
};
class B : public A {
method1() { }
}

Code:
A* a = new A();
a->method1(); // call B's method1?

Is it possible to call B's method1 in this case?

View 8 Replies View Related

C :: Way Recursive Calls Actually Works

Apr 27, 2013

This is simple recursive solution of Fibonacci number:

Code:

int fibo(int n)
{
if(n<=1)
return 1;
else
return fibo(n-1)+fibo(n-2);
}

Now the recursion will generate a large recursion tree, like if n=5, 5 will call (5-1), (5-2) or 4,3 . What I want to know is, will fibo(n-1) will be called 1st go all the way to the base case 1, then do the summation or fibo(n-2) will be called right after fibo(n-1) ?

View 6 Replies View Related

C++ :: Cancel Destructor Calls In Operator

Apr 18, 2014

Let's start with something from the c++ reference:

... delete[] is an operator with a very specific behavior: An expression with the delete[] operator, first calls the appropriate destructors for each element in the array (if these are of a class type) ...

I was wondering if I can tell delete[] to not call destructors, for example if I already know that the delete[] statement should be delete without []. That would be very useful for memory management/memory leak detection.

View 12 Replies View Related

C/C++ :: Multiple Malloc Calls On One Variable?

Feb 13, 2013

I'd like to know what happens if I use multiple calls to malloc() on one pointer (without free) in a single function. Here is the example:

void *data_thread(void *sockfd_ptr) {
  int sockfd = *(int *) sockfd_ptr;
  const int BUFSIZE = 5;
  char recvmessage[BUFSIZE];
  char *headerstr = NULL;
  char *newheaderstr = NULL;

[code]....

what happens with newheaderstr every time malloc() is called. There isn't a realloc() or anything. I didn't think it looked right to keep using malloc() like that.

View 4 Replies View Related

C++ :: Lines Without Semicolon - Function Calls?

Aug 28, 2013

The below code is taken from open source filezilla project

(FileZilla_3.7.3_srcfilezilla-3.7.3srcinterfacebookmarks_dialog.cpp)

Code:
#include <filezilla.h>
#include "bookmarks_dialog.h"
#include "sitemanager.h"
#include "ipcmutex.h"
#include "themeprovider.h"
#include "xmlfunctions.h"
BEGIN_EVENT_TABLE(CNewBookmarkDialog, wxDialogEx)
EVT_BUTTON(XRCID("wxID_OK"), CNewBookmarkDialog::OnOK)
EVT_BUTTON(XRCID("ID_BROWSE"), CNewBookmarkDialog::OnBrowse)
END_EVENT_TABLE()

I'm unable to understand what are these lines after the #include. They don't end in semicolons. Looks very much like function calls.

Are BEGIN_EVENT_TABLE, EVT_BUTTON and END_EVENT_TABLE function calls? Function calls should end with semicolons right?

View 5 Replies View Related

C++ :: Server Application - How To Delete Calls To New

Mar 29, 2012

I created a server application but i need to know how to delete my calls to new

Code:
CBaseServer::CBaseServer() {
}
CBaseServer::~CBaseServer() {
}
void CBaseServer::Start() {
struct sockaddr_in ain;

[Code] .....

Also when I call this..

Code:
new CThreadManager();

It gives me this warning...

warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized

View 10 Replies View Related

C# :: How To Store Multiple Function Calls In Array

Oct 9, 2014

My function "MatrixMul" returns an int array with multiple values Let's say, res[0] and res[1]

When I'm calling the array in a for loop for multiple times, and when I'm storing the results in another array, in each iteration the results are over-written with the new results.

If the first call returns [0,1] the array will store [0,1] at index [0] and [1], which is fine, but when I'm calling the function again, the new results are stored at the same indexes [0] and [1] How can I avoid that?

The code is:

class Hill_Cipher
{
string AtoZ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public string Hill_Cipher_Enc(string input, int[,] key)

[Code].....

For example, my outPut contains the following: "TH","IS","AT" when I'm calling the function with the first element of array "TH", it converts "T" to its equivalent number and apply some calculations and same with "H". Let's say the final answer is 20 for "T" and 30 for "H". The problem is that every time, encChars will store the values at index 0 and 1: encChars[0]=20 encChars[1]=30 When I call the function again it will store the new values at 0 and 1.... That's because I'm not changing the index value for encChars on each call, so how do I do that?

View 1 Replies View Related

C :: Multiple Scanf Calls Skip Printf Lying Between Them

Mar 31, 2014

Code:

scanf("%d", &a);
printf("A");
scanf("%d", &b);

prints "A" after calling scanf two times instead of between the calls (first scan, then print, then scan). I'm using GCC v4.6

View 7 Replies View Related

C/C++ :: Code That Recursively Calls Itself And Prints Given Digits In Ascending Order

Mar 15, 2015

I'm trying to implement a code that recursively calls itself and prints the given digits in ascending order, i.e. if the number is 5, then the function will print 1 2 3 4 5. I cannot use loops in any way!

The problem I have is with keeping my variable i at a set value each time the function calls itself.

void print_ascending(int n){
int i = 1;
if(i < n) {
printf("%d", i);
i++;
print_ascending(n);
}
}

Of course, the problem with this code is it will re-initialize the variable i to 1 every single time and infinitely loop to print 1.

View 11 Replies View Related

C++ :: Count The Repeated Numbers?

Jul 12, 2013

I am using this code that to check a set of values from a text file and show it on the output.

Code: void MatchNumber(int b) {
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");
double x1,y1,x2,y2;
while(theFile >> x1 >> y1 >> x2 >> y2 ){
rects.push_back(Rect(x1,y1, x2,y2));
}
int num=0;

[code]....

I want to calculate how many times the common number is repeated . So I have used freq[num] in that function. But I am getting the output like this-

Code:

The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

[code]....

So the freq[num] is only returning 1 instead of counting the total number of repeating which is wrong!! I would like to have somthing like this in my output -

Code:

The common number is = 5
The common number is = 6
The common number is = 4
The common number is = 5
The common number is = 5
The common number is = 8
The common number is = 9
The common number is = 6
The common number is = 6

[code]....

How can I do that?

View 3 Replies View Related

C++ :: How To Find Repeated Words

Aug 3, 2014

I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.

View 7 Replies View Related

C++ :: Repeated Digit In Integer

Oct 19, 2013

this code :

#include <cstdlib>
#include <iostream>
#define TRUE 1
#define FALSE 0
using namespace std;
typedef int Bool;

[Code] ....

Gives repeated digits in an integer but only in one condition : Only if the repeated digit is the result of n%10 where n is the integer the user writes. If the repeated digit is not the result of n%10 , then the compiler gives a wrong result.

so the question is : how to make this code gives the repeated digit in an integer (regardless the fact that the repeated digit is the result of n%10 or not and especially with making the minimum of changes on the code)????????? ?????

View 3 Replies View Related

C++ :: Print Repeated Array Of 2D?

Mar 23, 2014

Printing duplicate 2D array elements

if for 1D array

for (int i = 0; i<0; i++){
for (int j = i+1; j<0; i++)
{
if (arra[i] == arra[j]){
cout<<arra[i]<<endl
}
}
}

how would i do for 2D

View 5 Replies View Related

C/C++ :: Repeated Numbers In A Matrix?

Apr 18, 2014

Given the matrix MxN, check if there are repeated numbers.

View 8 Replies View Related

C++ :: Counting The Repeated Number?

Jul 12, 2013

This function check a set of values from a text file and show it on the output.

void MatchNumber(int b){
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");

[Code]......

I want to calculate how many times the number is repeated. So I have used freq[num] in that function. But I am getting the output like this-

The common number is = 5
The 5 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

The common number is = 9
The 9 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

So the value of freq[num] only shows 1 instead of calculating the number of repetition.

View 3 Replies View Related

C/C++ :: Using Strings To Find Out If A Name Is Repeated?

Feb 10, 2014

I have to write a code that will read in n amount of names and the names. Then it will tell me if the first name entered has been repeated or not.

This is my input:

5 Bush Reagan Lincoln Bush Obama

This is my output:

First name in list is not repeated.
First name in list is not repeated.
First name in list is repeated.
First name in list is not repeated.

I would like to just give one answer; if it is repeated then the output should simply be "First name in list is repeated."

If the answer is that it was not repeated, I would like the output to say once "First name in list is not repeated."

// lastnames.c

#include <stdlib.h>
#include <stdio.h>
int main(void) {
char FIRST[25];

[code]....

View 2 Replies View Related

Visual C++ :: Disable CCheckListBox Items Without Access To Code That Calls AddString

Apr 19, 2013

I need to be able to disable the items on a CCheckListBox but I can't change the code that calls AddString. I know I can use the CCheckListBox::Enable function to disable an item if I have an index but I don't have the index which would be provided by AddString.

I've tried intercepting the LB_ADDSTRING message and then looping through the items in the control but the string has not been added at this point so the last item in the list is never disabled.

I used Spy++ to see what messages were being sent and I noticed that LB_GETTEXT was sent so I tried intercepting this message (ugly hack) but this caused my app to hang - I assume because of the number of times the message is sent. Is there a way to disable the items?

View 10 Replies View Related

C++ :: Repeated Word Detection Program?

Mar 6, 2015

In the C++ book Programming: Principles and Practice Using C++, there's an example code like this for detecting repeated words:

Code:
#include "std_lib_facilities.h"
int main() {
int number_of_words = 0;
string previous = " "; // previous word; initialized to "not a word"
string current; // current word
while (cin >> current) // read a stream of words

[Code].....

The header file in there is sort of like a set of training-wheels for students who are complete beginners to the language; the function keep_window_open() is defined in there and it does just that on Windows systems where the output window closes too fast (in the case of the function, it's just like cin.ignore(), except it waits for you enter a character, like 'j', before it exits); programs on my Windows laptop work fine on Code::Blocks, but when I create a .exe file for them and double-click that file, it does actually close too quickly for me to be able to see the output (if it's a program like the generic "Hello World!" program that just outputs text to the screen and then exits - so all I see is the output window just flash-by really fast in those cases).

Anyway, as for the problem I'm having with the code: there are no error and compile- or link-time, but it does behave strangely at runtime, where the part inside the curly-braces of the while-loop doesn't execute at all.

View 3 Replies View Related

C++ :: How To Count Repeated Numbers In Array

Jan 30, 2015

So I already gave this a go and will post my code below. The question is about the last loop before the program cout's. i thought the count would keep track of the repeated numbers so i could display them but it does not. I italicized the loop i am referring to. or at least i tried to xD

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int inputs[30];
int numofloops;
int maxvalue = inputs[0];

[Code]...

View 1 Replies View Related

C/C++ :: Writing Repeated Lines To A File?

Aug 26, 2014

I am working on a problem for the CS50 online course through the Harvard web site. I am trying to re-size a bmp image. They gave us a small program that copies a bmp image and we are to modify it to re-size the image. Here is the page [URL]..... Any way I am trying to move the file position indicator backwards so I can read the same line from the input file. So I can resize the file vertically I have the image resized horizontally but it keeps over writing the same lines vertically.

/**
* bmp.h
*
* Computer Science 50
* Problem Set 5

[Code]...

View 4 Replies View Related

C/C++ :: Finding First Non-repeated Digit In Array

Aug 26, 2014

With out sorting and if the array size is changed and filled with different elements, mayb some that are all duplicates(in that case display message that says "No nonrepeated digits".

This seemed like a simple task but im failing to grasp some concept. if the array is 2,0,38,2,3,1,3 the first non repeated is 0.
nested loop is how i went. i feel like im going to far with the counters than need be. just need first non repeated. if n equals 2 an o equals 0. and it iterates comparing 0,38,2,3,1,3 to n which is 2. repCount will b 1. if repcount was 0 then n would be the first non repeated number. im trying to consolidate my if else statements so there are not so many. This program fails if the array gets bigger say 2,45,2,7,1,8,9,45,1,10 .....

for (n=0; n<sizeof(digits)/sizeof(int); n++) {
if(repCount<2) {
// nonRepCount=0;
for (o=n+1; o<sizeof(digits)/sizeof(int); o++)

[Code] .....

View 1 Replies View Related

C :: Replace Repeated Elements Within 2D (10x10) Int Array

Mar 20, 2014

I have generated a 10x10 integer matrix, by way of a 2 dimensional array, the elements are randomly generated and lie on 1 <= z <= 5. I am in need of an efficient method of setting all adjacent "duplicates" (repeating elements) of length 3 or greater to the integer six (6). The source for the brute method follows for clarity.

Code:
46 for(row=0;row<10;row++)
47 {
48 for(col=0;col<10;col++)
49 {
50 board[row][col]=rand()%4+1; //filling matrix here

[Code] .....

I know there must exist a much more elegant approach than listing out all permutations.

View 1 Replies View Related

C :: Read In N / Then N Words And Check To See If First Word Is Repeated

Sep 23, 2013

Read in n, then n lastnames, and check to see if the first in the list is ever repeated again.Here's what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
int strcmp(char *w1, char *w2);
int main() {
int j, n;
char string1[30], string2[30];
}

[code]....

I see the problem is that it lies within n amount of string that I am not going through every string to compare to the first one.How will do compare every string to the first one?

Current output:
3
alex
alex
alex
Not repeated

3
alex
ash
peter
Not repeated

View 2 Replies View Related

C :: Card Shuffling - How Numbers Are Not Repeated In Function

Jan 27, 2014

I found a card shuffling function on a long dead thread.

Code:
for (int x = 52; x > 0 ; x--)
{ y = rand() % x;
temp = deck[x];
deck[x] = deck[y];
deck[y] = temp; }

I do not understand how numbers are not repeated in the function. It seems like it would be possible to get 2 cards with the same number with the above function.

I also am getting incorrect numbers. It seems like I should only get numbers between 1 and 52 (which is what I want). However, I am getting the number 0, and some number between 1 and 52 will be missing, but I will have a total of 52 unique numbers.

I played around with using 51 instead of 52, x > 1, and changed to --x and none of those produced the desired results.

View 5 Replies View Related







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