C++ :: Making A Sorting Function?

Nov 23, 2013

#include<iostream>
#include<fstream>
#include<iomanip>

[Code].....

make it sort ascening wise for salaries and have the occupation sort with it.

View 6 Replies


ADVERTISEMENT

C++ :: Making Float To String Function

Jan 23, 2015

I have this:

void reverse(char *in, int isize) {
char t = 0;
for( int a = 0; a < isize / 2; a++ ) {
t = in[a];
in[a] = in[(isize - 1) - a];
in[(isize - 1) - a] = t;
[Code] .....

s:
float:123456
s:123456

The function i made is working fine, exacly how cout << float is working. The problem is i think my function is not really effective. By that i mean my function is doing alot of useless stuff to do what i want and there have to be a better way.

The rule is that you can not use other functions, only playing with loops and operators.

View 5 Replies View Related

C :: Making Function That Will Return Pointer To Long Variable?

Feb 7, 2014

I am making a function that will return a pointer to a long long variable. For example, I have the next variable prototype: Code: long long funcName(long long x, int s); I want to change the return value, and the first parameter to pointers to long long.

View 4 Replies View Related

C++ :: Bubble Sorting With Function Templates

Jun 21, 2013

i'm new to C++ i came across this bubblesort program earlier relating to class templates i was wondering how to make this into simple function templates

#include<iostream>
#include<iomanip.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
template <class t>
class bubble

[Code] ....

View 3 Replies View Related

C++ :: Sorting Function - Vector Swap

Jun 26, 2013

writing a sorting function that has an argument for a vector of ints rather than an array; it should use a selection sort algorithm.Here is what I have:

#include <iostream>
#include <vector>
#include <conio.h>
using namespace std;
void fillVector(vector<int> &aVector);
// PRECONDITION: number declared size of array a.
// POSTCONDITION: number_used is the number of values stored in a
//a[0] through a[number_used-1] have been filled with nonnegative int.

[code].....

View 7 Replies View Related

C :: Passing Array Of Struct To Sorting Function

Mar 6, 2015

how is this done not really sure .

Code:
//prototype
void improvedbubblesort (struct team Table[]);
//this is defined out side of main

[Code]....

the whole code is very long but can post if necessary . Basically i get no errors in this but its not sorting them . Think its in the way i pass the array of struct .

View 3 Replies View Related

C :: Array Sorting Program That Works With Recursive Function

Mar 10, 2013

i want to write an array sorting program that works with recursive function.but i can not do it.

my algorithm

Recursive
find the min value
find the min value and save it
find the min value and save it and remove it from loop
put the rest in loop again
find the min value again
..
...

i didnt write the function because i dont know how will it work

Code:

#include<stdio.h>
#include<stdlib.h>
#define s 5
void main() {
int a[s]={25,3,2,4,1},c[s]; // c[s] for new sorting
int i,ek,j; //ek = min

[Code]....

View 7 Replies View Related

C++ :: Sorting Vector Of Complex Objects Using Custom Function

Mar 6, 2014

I am trying to use std::sort to sort a vector of complex objects using a custom function. However, it keeps erroring "Unresolved overloaded function type".

encounter::encounter(){
// ... cut
std::sort (allpeople.begin(), allpeople.end(), sortByInit);}
bool encounter::sortByInit (character& a, character& b) {
if (a.getinit () == b.getinit ()) {

[Code] ....

View 6 Replies View Related

C++ :: Making Function To Read Unsigned Integer Into Variable Of Type Unsigned Short Int

Apr 3, 2014

How can i write a function that will read an "unsigned integer" into a variable of type "unsigned short int"? i can not use cin >> inside the function.. so i am looking for atleast a hint!

View 16 Replies View Related

C++ :: Sorting Data Based On Some Metric - Function Pointer Syntax

Nov 20, 2014

I have a piece of code that sorts data based on some metric. The some metric is something I now want to make flexible so I can easily switch between and compare metrics. To do this, I want to pass the function to use as a parameter to the method that does the sorting (and other stuff). However, I'm having problems figuring out the syntax. Also, I think my [temporary] organization of code is violating a lot of basic code design principles.

To make the function pointer passable, I defined the "typename" in the header where the function is located (it is part of a struct, "Data"):

// Below the struct definition of Data
typedef double (Data::*CostF)(unsigned l, double W) const;

The two example functions I want to use are defined in that struct ("Data"):

// Inside the struct definition
inline double someExampleCost(unsigned l, double W) const {
// Returns some basic calculation
}

The function that uses it is part of a different class (that holds a reference to the first class, in case that matters; I feel like I'm doing something odd here, because I'm binding a member function in the definition/passing, but never referencing the object). It looks like this:

// Inside another class ("Foo")
inline void DoSomeStuff(double& ECost, double& TCost, CostF cost) {
// Irrelevant stuff here
std::sort(vector.begin(), vector.end(), [&](unsigned a, unsigned b){
return (*cost)(a, W) < (*cost)(b, W);
});
// More irrelevant stuff here
}

The error shown is "operand of "*" must be a pointer". If I remove the '*':
[code]return cost(A, W) < cost(b, W);

the error becomes: "expression must have a (pointer-to-)function type."

The call to this function is, currently, just in the main function, as I'm just testing before I wrap it into real code. It looks like this:

// In main
Foo bar; // Make an object of the struct that has the "sorting" function
CostF costFunction = &Data::someExampleCost;
// Bind to the Cost function bar.DoSomeStuff(varA, varB, costFunction);

This bit shows no errors by itself. So, my questions:

a) Clearly I'm missing the insight into Function Pointers. I'm comfortable with regular pointer stuff, but I can't wrap my head around FPs, partly due to the awkward syntax.

b) I'm very uncomfortable with the fact that I'm binding a member function of a class, but never try to reference an actual object of that class. This is probably a big part of why it's not working, but I can't seem to bind a function belonging to a specific object. I thought of doing

// In the main again
Data d; // Construct the object, which contains big lookup tables
Foo F(d); // Construct the object, which only holds a reference to a Data object
CostF costFunction = &d.someExampleCost; // Bind to the Cost function of that object

but that doesn't work ("a pointer to a bound function may only be used to call the function").

View 4 Replies View Related

C++ :: Making A Game With GUI

Feb 27, 2015

Here's my game, what do I need to learn to make a basic GUI? (Easiest way possible for now).

--NOTE, the code was a bit too long for me to post. I can add it if it is necessary. Basically all I want are 4 buttons on the main screen, one that says "Arena," "Store," "Stats," and "Exit."

There will of course be sub menus to each option, but we will get to that later.

View 1 Replies View Related

C++ :: Making DLL Of EXE Project

May 28, 2013

I have project that is on c++. it runs fine. i want to use it in my C# application as a dll. i have created its dll and but firing exception of "interprocess communication".

Is this a doable task that creating dll of an exe project and using it in C# application?

View 1 Replies View Related

C++ :: Error While Making DLL

Dec 17, 2013

So I tried to find some youtube videos on how to make a DLL, I found one, I also found several topics (like on msdn and stuff), but I have this code

header

#include <WinSock2.h>
#include <WS2tcpip.h>
#include <Windows.h>
#include <string>
using namespace std;

#pragma comment(lib, "ws2_32.lib")

[Code] ....

And I'm getting these errors:

1>error LNK2001: unresolved external symbol "private: static char * PathSocket::cBuffer" (?cBuffer@PathSocket@@0PADA)
error LNK2001: unresolved external symbol "private: static unsigned int * PathSocket::socket" (?socket@PathSocket@@0PAIA)
error LNK2001: unresolved external symbol "private: static void * PathSocket::hIDTask" (?hIDTask@PathSocket@@0PAXA)

WHY is there static, and what does dllimport/dllexport does? also there are NO tutorials with variables inside dll >.<

I've been following this [URL] ..... and the video I already lost, however there's no

#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport)
#else
#define MATHFUNCSDLL_API __declspec(dllimport)
#endif

in the video, why do we have to use that? [URL] .....

View 19 Replies View Related

C/C++ :: Making Tic Tac Toe Without Arrays?

Nov 13, 2014

I am trying to get this to work without arrays. At the moment all I am trying to do is allow it so that when the user presses 1 the board prints with 1 replaced by X, tell me where am i going wrong. I know its not finished.

#include <stdio.h>
#include <stdbool.h>
char a = '1';
char b = '2';
char c = '3';

[code]....

View 3 Replies View Related

C :: Making HTML Shapes

Oct 13, 2014

So basically I have to write a C program that, when opening the html file in a browser, looks essentially like this: (Size, position, color of the shapes doesn't matter so long as I have one of each shape and the box surrounding them. Words up top dont matter either.)

This is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#define FILENAME ("A4P1.html")
[code]....

Anyways i can get the individual shapes, but I don't know how to get all the shapes to appear at once..

View 6 Replies View Related

C :: Making A Teapot With Triangles

Oct 15, 2013

i have an assignment where i have to draw a teapot using triangles, and are struggling with the part where i have to color it. Here is an link to the assignment URl....

I have managed to draw the teapot and translated it onto the screen. the part i need support with is making a bounding box for the triangle and coloring it.

View 5 Replies View Related

C++ :: Making A Table For 10 Employees

Apr 22, 2014

I have to make a table for 10 Employees to look like this:

Employee ID Gross Pay Net Pay
101 540.58 480.80
158 796.32 630.20

How can I do this? This is my code so far.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void get_emp_rec(int &id, double &prate, double &hours) {

[Code] ....

View 2 Replies View Related

C++ :: Making A Countdown Timer?

May 17, 2013

I'm creating a game in which i.need player to.answer.my question within 10 seconds...

So I need a code for this timer... I don't want code to be paused by sleep or delay functions.. But I need that it waits.for 10 seconds.. and if user types answer in between.. it.reads it

And if player.doesn't answers it within 10 sec.. it displays a message

View 2 Replies View Related

C++ :: Making Octagon Out Of Right Triangles

Jun 28, 2014

One exercise says that, "Define a right triangle class. Make an octagonal shape out of eight right triangles of different colors."

Making such a class isn't difficult. I wrote it as follows:

#include "Simple_window.h"
class right_triangle : public Shape {
public:
right_triangle(Point p, int l, int sh): c(p), _long(l), _short(sh)

[Code] ....
But it sounds that making an octagon using eight right triangles isn't possible!

View 2 Replies View Related

C/C++ :: Making A Simple Animation

Sep 20, 2014

I wish to create a simple animation, similar to the pong game but completely automatic (i.e. both sides play against eachother sort of like in a screensaver of sorts).

I am clueless on to even start tackling this, what tools to use and how to use them, to make them do what I want. I have had some experience with C++ scripting while modding Fallout 3, but I'm not sure how similar the scripting system available in the SDK for that game, is to the real thing.

Like I was saying I want to create a simple animation where two AI blocks try to prevent a ball from reaching the wall behind them.

View 3 Replies View Related

C/C++ :: Making Octagon Out Of Right Triangles?

Jun 28, 2014

One exercise says that, "Define a right triangle class. Make an octagonal shape out of eight right triangles of different colors."

Making such a class isn't difficult. I wrote it as follows:

#include "Simple_window.h"
class right_triangle : public Shape {
public:
right_triangle(Point p, int l, int sh): c(p), _long(l), _short(sh) {
add(Point (p));}
void draw_lines () const

[code]...

But it sounds that making an octagon using eight right triangles isn't possible!

View 4 Replies View Related

C/C++ :: Making Addition Loop?

Nov 19, 2014

What my ultimate goal here is to make a program that asks the user how many numbers they would like to add followed by asking the user what numbers they want to add. I want the amount of numbers they can add to be infinite and have the loop continue adding the numbers until it reaches the final number. I just need to know how to do this.

Here's my code:

#include <iostream>
#include <string>
using namespace std;
int main() {
//variables
int amount;
float num;
float sum;

[code]....

View 3 Replies View Related

C/C++ :: Queue Making Using Arrays

Nov 11, 2014

I'm trying to write a code that proves a queue like fifo (first in first out). I have four characters :

p(rint),e(nqueue),d(equeue) and q(uit).

The problem is when I press d a first character must get rid of, but not. When I press d the numbers get double.

Example input:
e 2 3 9 8 7
p
2 3 9 8 7
d
p
3 9 8 7
d
p
9 8 7

#include <stdio.h>
void enqueue(int queue[], int newnum, int *tail_p, int maxsize);
void deque(int queue[], int *tail_p, int *elem);
void printqueue(int queue[],int count);

[Code] ....

View 1 Replies View Related

C++ :: Making Constructor For Array Of Character

Jan 16, 2015

Code:
class Robot{
char name[15]; //assign to char n
int x, y , direction;
void ToString(int d);

[Code]......

how do i assign char name[] in the class to char n in the constructor?

View 3 Replies View Related

C :: Making Integer From Pointer Without A Cast

Dec 15, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
#define CLASS 4
#define STUDENT 11
#define GRADE 5

[Code] ....

Giving me that error on 75:10
avesub+=grade[k];
and 90:17
donkeypunch+=grade[j][k];

not sure exactly why

View 8 Replies View Related

C :: Making Header Files With Extension?

Mar 6, 2015

I have a problem with making header files in c, i get the code written only in main.c and then i have to create a files with extension .h and extension .c but how to do it.

View 4 Replies View Related







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