C/C++ :: Write Function For Destruction Of Planetary System Solid

Dec 18, 2014

I have to write a function for the destruction of the planetary system "solid". With the destruction of the planetary system, the asteroids where the gap between this one and the object, is smaller that "gap" will also be destructed. (so, they have to be deleted) The asteroids for which the gap is greater are converted to free-floating planets so they have to be inserted into the tree of free-floating planets. The total cost of the transport of all the asteroids that are converted into free-floating planets in the tree of free-floating planets should be $O(n)$, where $n$ is the maximal between the elements of the tree of free-floating planets of the star system to which the object belongs and the elements of the tree of asteroids of the planetary system of which the object has identifier "solid". The field "gap" of the new tree should have the value $0$. The destructed planetary system should be deleted from the list of planetary systems of the star system to which it belonged. (The tree of free-floating planets is not a binary search tree)

I have done the following: [URL]

Is the way I deleted the nodes correct??

View 4 Replies


ADVERTISEMENT

C++ :: Calling Dynamically Loaded Function From DLL Destruction Error?

Apr 18, 2013

I have two projects (Projects A and B). Project A is a dll project, defining a function called "regex".

Project B dynamically loads this DLL, and calls Project A's "regex" function via LoadLibrary/GetProcAddress.

Regex takes a pointer to an std::vector (std::vector<std::cmatch>).

When debugging ProjectB, I can see that, within the code from ProjectA (in the "regex" call), a loop that loops through the elements of the vector outputs all the elements in the vector to console as expected. But the loop in ProjectB ( which executes after ProjectA), which also loops through the vector, and, is supposed to output the elements of the vector, outputs empty strings, not, as I would expect, the same strings (which contain results), as in the loop in Project A.

How is this happening. Does this have anything to do with it being a DLL, and, maybe, somehow values/memory addresses (or something similar) of the vector/its elements being destructed across the Projects/Dlls?

Output and Code See Below:

Output Loop in A:

Un
Un

Output Loop in B: (empty) (i.e. none)

Project A DLL Header (interface.h):

#include "stdafx.h"
#include <vector>
#include <regex>
extern "C" {__declspec(dllexport) int __cdecl regex(std::string target,std::string rgx, std::vector<std::cmatch*>* matches);}

[Code].....

View 8 Replies View Related

C :: How To Write A Content Manager System (CMS)

Feb 17, 2014

how can i write a contact manager system(CMS) in c ?

View 2 Replies View Related

Visual C++ :: System Access Violation Exception / Attempted To Read Or Write Protected Memory

Mar 17, 2013

I have CAN Dll program for my application,which was separately used.Now I have included the Drivers program into my application Program and I am having this error System Access Violation Exception:Attempted to read or write protected memory.i am attaching the Dll code and Application code which is throwing this error.

[CODE]

The CAN Dll Code

int receive_data(unsigned char *data_output, int *MsgId, XLportHandle g_xlPortHandle){
XLstatusxlStatus, xlStatus_new;
XLevent xlEvent;
unsigned intmsgsrx=RECEIVE_EVENT_SIZE;
char *local_data ="11111111";
DWORD status;
xlStatus_new = xlSetNotification(g_xlPortHandle, &h, 1);

[code]...

My Application Code which is the receiver thread for accessing the messages got onto the CAN bus.

DWORD WINAPI Rcv_Msg(LPVOID param){
int*MsgId = new int;//msg id from CAN
intRcvVal;//0 = there is data in the queue; 1 = there is no data
unsigned int uMsgId;
*MsgId = 0;
unsigned char CanData[8];

[code]...

View 1 Replies View Related

C++ ::  Improper Destruction Of Objects

Feb 2, 2014

I have two simple classes: Author and Book. Class Author contains class Book as a member. Additionally i have a list of Book objects within each Author class.

//Book.h
#include <iostream>
#include <string>
#include <cstring>
class Book{

[Code] ....

//output WITHOUGHT debugging
variable bname before exiting my Book constructor:A Frogs thug life
Book's name:A Frogs thug life
Book's realese date:1993

Author's name:Alex
Author's birth date:1892

variable bname before exiting my Book constructor:Life on Jupiter
destructor of Book called
Book's name:▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌♀
Book's realese date:1991
Press any key to continue . . .

Basically these are my problems:
- Why is the Book's instance's destructor called right after my program exits Book's construcor
- Does Book's name(during the output of my Print() method) print these wierd symbols due to the fact that this instance of Book got destroyed?
-if this instance of Book actually got destroyed before the Print() method,why the hell is it able to print the Book's release date?

View 2 Replies View Related

C++ :: Singleton Destruction Order

May 28, 2012

I've been upkeeping a mess of a code recently, that uses "pseudo" singletons. Basically, the current code has "Initialize_All" static functions that initializes all the singletons in a given order. At the end of the program, we call "Destroy_All", and destroy everything in the reverse order.

The code is actually heavilly dll'ed, and Initilize_All and Destory_All are referenced counted. We ask that any client who uses our code call Initialize_All first and then Destroy_All when they are finished. The first Initilize_All will initialize everything, and the last Destory_All will delete everything.

This is showing its limits.

I'd like to move us to a fully singleton design. The singleton pattern means we don't have to use an Initilize_All, and each singleton can manage construction dependencies by itself (we are mono-threaded).

Each singleton is "clean", so it is cleans itself up at dll destruction.

The big question is this one:

If there is a singleton dependency during destruction, eg: ~A requires an instance of singleton B (which is in another DLL), are we guaranteed proper behavior?

Or, is there an "Static de-initialization order fiasco"?

If yes, are there any design that can combat this fiasco, short of having each singleton register itself in a manager, that will destroy them in reverse order?

View 6 Replies View Related

C++ :: Vector Causing Memory Errors On Destruction?

Sep 10, 2013

std vector seems to cause errors when destructing here some simplified code:

#include <stdlib.h>
#include <stdio.h>
#include <vector>
class Foo{

[Code]....

View 5 Replies View Related

C :: System Call For A Pause Function

Jan 20, 2014

I know there has to be a system call for a pause function. I simply want the program to pause for a few seconds before executing the next line of code. I do NOT want the user to enter a keypress, just pause the output or code execution for a few seconds.

system (pause); waits for keypress right? I just want it to wait 3 seconds before proceeding. I know it should take an argument for milliseconds right? Also, this is for a homework assignment I have already completed, just doll'in it up a bit for extra credit...maybe...

View 7 Replies View Related

Visual C++ :: How To Use 2 Command In System Function

Feb 7, 2013

I want to run Unhidden.exe in drive N: and send char to that program. I use function like this

Code:
system("N:/Unhidden.exe");

It can open Unhidden.exe but it run in visual studio 2010Projects . I try to use command N: and Unhidden.exe in cmd it can run in drive N: . So I try to use function like this

system("N:");
system("Unhidden.exe");

but it not found Unhidden.exe . How to use 2 command in sytem() function ?

View 4 Replies View Related

C++ :: Program For Billing System - Regular Package Function

Jan 5, 2015

I have programmed a program for billing system. I have used parameters and arrays. All the functions are working except a one function. (Regular package function).

#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
void main(int &minutes, int &minutesd,int &minutesn) {

[Code] .....

View 3 Replies View Related

Visual C++ :: How To Modify System Menu To Execute A Function

Feb 11, 2013

I wish to add the item 'Website' to an MFC Dialog app System Menu so that it can activate the following method:

Code:
void CMyDlg::OnWebpage()
{
ShellExecute( NULL, NULL, _T("[URL]..."), NULL, NULL, 0 );
}// OnWebpage()
I have tried this:

Code:

#define IDM_WEBSITE (WM_USER + 101)
//..
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
pSysMenu->AppendMenuW(MF_STRING, IDM_WEBSITE, _T("Website"));
}

[Code]...

The code compiles without error but and the 'website' item appears on the System Menu but it doesnt do anything.

I've inspected the following but don't really understand how it works and it seems to me there should be a simpler way to accomplish my end.

Modifying the System Menu By John Simmons 26 Jan 2007 [URL]....

View 8 Replies View Related

Visual C++ :: System Function Fails To Parse Argument

Apr 29, 2014

I have a very strange problem with the system() function (on XP).

I have the following code:

Code:
char *text1 = ""A SpaceAction.bat" fred";
char *text2 = ""A SpaceAction.bat" "fred"";
int main(int argc, char *argv[]) {
printf("%s
", text1);

[Code] .....

When I run it where "A Space" is a directory with a space in the name, this is the result:

Code:
"A SpaceAction.bat" fred

F:Test>echo Testing
Testing
"A SpaceAction.bat" "fred"

'A' is not recognized as an internal or external command, operable program or batch file.

It seems that the double quotes round an argument make the parsing of the command fail.

View 1 Replies View Related

C/C++ :: Booking System - Comparing 2 Char Variables In Check Function

Aug 31, 2014

I had problem in comparing 2 char vairable in check function

if(room_no==r)

variable r take input from user and compare to room_no read from file.

#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<dos.h>
#include<string>
#include<stdlib.h>

[Code] .....

View 2 Replies View Related

C++ :: Write Function That Doubles Every Element?

Dec 5, 2013

how would one write a function that doubles every element of a 20×10 2-dimensional array? this is what i've got so far.

double arrary [i][j];
for(double i=0; i<20;++i) {
for (double j=0;j<10;++j) {
array[i][j] =

[Code]......

View 5 Replies View Related

C++ :: Write A Function Returning 2 Values?

Jul 23, 2013

So I have a function like the one below

bool get_array( float input_param, vector<int>& output_param ){
// some code that handles output_param output
if( error ) return false;
}

So basiclly this function must return 2 value well one of the value is just a bool returning whether the procedure doesn't fail at some point or not.

is there any better way to write this function ?

View 7 Replies View Related

C Sharp :: Write Log Using Static Function?

Oct 30, 2012

In my code, I wanted to write log exception to some file.

So I created a Utility class & wrote a static method in that to write log message to file.

public static void WriteLog(string message) {
  using (FileStream fs = new FileStream(@"c:log.txt",  FileMode.Append)) {
     using (StreamWriter streamWriter = new StreamWriter(fs)) {
          streamWriter.WriteLine(message);
     }
  }
}  

This works fine so far but I fear if two methods call this function simultaneously.. what will happen? Also, I want to access this same Utility library in my other "WEB" projects... will it work there too?Or else.. what will be the best way to log exceptions in any project?

View 4 Replies View Related

C :: File Write And Read As A Function Error

Sep 27, 2014

called object 'fptr_in' is not a function or function pointer
called object 'fptr_out' is not a function or function pointer

what can i do for the errors?(i mustn't use loop and arrays for the code)

Code:

#include <stdio.h>
void sum_of_2nd_and_3nd( FILE* fptr_in, FILE* fptr_out);
int main()
return 0;
}
void sum_of_2nd_and_3nd( FILE* fptr_in, FILE* fptr_out){
}

[code].....

View 2 Replies View Related

C++ :: Write A Function To Modify The Input String?

Oct 8, 2014

i have to write a function to modify the input string by substituting each alphabetical character. for example, 'Programming' to 'Rtqitcookpi' (mod_int = 2).

View 1 Replies View Related

C++ :: Write A Function That Receives Two Arrays Of Integers

Feb 19, 2013

There is one question :

Considerint A[10]={ ....................}; // already filled
int B[10]={ ....................}; // already filled

Using PIONTER NOTATION ONLY, write a function that receives two arrays of integers like A and B above. The function should swap the values in A and B. You may NOT use array notation [ ]. Also, you have to use pointers to move among array cells. Note: Both arrays are of the same size, and size should be variable in the function.

View 3 Replies View Related

C++ :: Write A Recursive Function Called Sumover

Mar 8, 2014

Write a recursive function called sumover that has one argument n which is an unsigned integer. the function returns double value which is the sum of reciprocals of the first n positive integers =.

for example sumover 1 returns 1.0
sumover 2 returns 1.5 like 1/1+1/2

View 11 Replies View Related

C++ :: Write Program That Uses Function To Compute The Cost?

Nov 1, 2013

Write a program that uses a function to compute the cost of a pizza with given diameter and the number of toppings. Constant will be the cost per toppings and cost per square inch. It will contain a reputable structure as well.

diameter=17
number of toppings=3

//complier directives
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>

[Code].....

View 6 Replies View Related

Visual C++ :: Write A Function With Array And Int Parameter?

Nov 25, 2012

i need to write a function with an array parameter and an int parameter.

that array has to be filled with first 10 prime numbers that are exact or higher than the int parameter...and then i need an average value of those 10 prime numbers...

The problem is im not really sure how i should do the part to fill the array with prime numbers that are higher than that int??

Code:

int avgprimearray (int higharray[], int somenumber){
}

View 1 Replies View Related

C :: Write A Function That Computes And Returns Score For A Permutation

Mar 21, 2014

Write a function that computes and returns the score for a permutation, i.e. the number of reversals required to make arr[0] == 1.
HAVE TO USE FOLLOWING FORMAT:

Code:
// POST: Returns the number of reversals needed to make arr[0] == 1
// if the reversal game were played on arr
// Note: If arr[0] == 1 initially, then score(arr, n) returns 0 AND this is what i could muster;
[code]....

View 2 Replies View Related

C :: How To Write One Binary Tree Function To Sort The Data

Dec 2, 2014

The Problem You are part of a company writing a spreadsheet program. As you know, spreadsheets can be sorted on any column. You're part of the project is to write one binary tree function to sort the data [Hint: use different fields when inserting nodes in the tree.] and a second function to list it in either an ascending or descending sequence. [Note: Each of these functions may actually need to be a set of related functions.]

For sample data you will have a disk file containing information about Shakespeare's plays. Your first function should create a tree based on the sort selected by the user and the second function to display the data in the sequence selected by the user. Regardless of the column being sorted, data in individual records always be displayed in the same line of the output.

Input : Each record will contain the following information: First Performed 9 characters Printed 5 characters Title 26 characters Type 7 characters

Output : Tabular output should be aligned in columns with two spaces between each. All columns should have headings. It should be sorted on the column specified by the user.

Example (This sample data provided so you can test your program.) If the data is:

1595-96 1600 A Midsummer Night's Dream Comedy
1594-95 1623 Two Gentlemen of Verona Comedy
1596-97 1623 King John History
1597-98 1598 Henry IV, Part 1 History
1611-12 1623 The Tempest Comedy
1602-03 1623 All's Well That Ends Well Comedy

[Code]...

Source: [URL]...

Possible outputs are

1 - for a sort by title: First
Performed Printed Title Type
--------- ------- -------------------------- -------
1595-96 1600 A Midsummer Night's Dream Comedy
1602-03 1623 All's Well That Ends Well Comedy
1606-07 1623 Antony and Cleopatra Tragedy
1599-1600 1623 As You Like It Comedy

[Code]....

2 - for a sort by first performed: First
Performed Printed Title Type
--------- ------- -------------------------- -------
1590-91 1594? Henry VI, Part 2 History
1590-91 1594? Henry VI, Part 3 History
1591-92 1623 Henry VI, Part 1 History
1592-93 1623 Comedy of Errors Comedy
1592-93 1597 Richard III History

[Code]....

View 1 Replies View Related

C/C++ :: How To Write A Function For A Single Turn Involving Die In A Game

May 16, 2014

So basically it consists of implementing a single turn for the game called 'pig' and printing out scores and probabilities of those scores. So this is what I have thus far :

int randomNum (int min, int max) {
return min + rand () % (max - min + 1);
} int singleTurn (int holdValue) {
int totalRoll = 0;
int score = 0;
do {
score = randomNum(1,6);

[code]....

View 13 Replies View Related

C/C++ :: Write A Function Fibonacci That Takes Int Indicating Length

Sep 2, 2014

We have to write a function named fibonacci that takes an int indicating the length of the series and then store it in an array of size 20 printing the sequence from largest to smallest. Here is the small bit i have so far:

#include <iostream>
#include <iomanip>
using namespace std;
void Fibonacci( int );
int main( ) {

[Code] ....

I just need something to get me on the right track.

View 1 Replies View Related







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