C++ :: How To Restore Consecutive Enumeration

May 10, 2014

I have an array of groups of numbers (I call them classes), that might look like this:

Code: static const int arr[] = {1,1,3,3};
std::vector<int> classes( arr , arr + sizeof(arr) / sizeof( arr[ 0 ] ) );

or like this

Code: static const int arr[] = {1,3,3,3,5,5,6,8};
std::vector<int> classes( arr , arr + sizeof(arr) / sizeof( arr[ 0 ] ) );

The groups of numbers are in an increasing order, but not numbered consecutively. So, would I would like to have is this

1,1,2,2

and

1,2,2,2,3,3,4,5

A loop like this

Code: for ( int i = 1; i < classes.size(); i++ )
if ( classes.at( i ) > classes.at( i - 1 ) )
classes.at( i ) = classes.at( i - 1 ) + 1;

does not work, because it changes the preceding value in the group, thus destroying the group. How would you do it?

View 9 Replies


ADVERTISEMENT

C++ :: Restore Keyboard Stdin After Reading From Pipe?

Apr 25, 2014

I use the following code segment to read and output the text piped to a program. If there is no piped text, the code segment is skipped and then the program continues. What I need to do is restore stdin to the keyboard after reading from the pipe. I use the PeekNamedPipe() and ReadFile() because reading from stdin blocks until it has something, and I don't want that to happen. After reading from the pipe, the program begins to execute, and the main loop can be paused and it prompts for a command. I just can't figure out how to restore input to the keyboard. Obviously the platform is Windows.

char char_buffer[1024];
DWORD bytes_read;
DWORD bytes_avail;
DWORD dw;
HANDLE stdin_handle;
bool is_pipe = false;

[code]....

View 4 Replies View Related

C++ :: Difference Between Enumeration With And Without Name

Jun 14, 2014

Code: enun{go, stop, ready, halt}
vs
enum status{go, stop, ready, halt}; and where is enumeration with name is benefficial.

View 7 Replies View Related

C++ :: Declaring Enumeration With First Three Prime Numbers?

Jun 18, 2013

I would like to declare an enumeration with the first three prime numbers. For example

enum { THE_FIRST_PRIME = 2, THE_SECOND_PRIME = 3, THE_THIRD_PRIME = 5 };

What would be the best names for these enumerators? Or the names I used are good enough?

View 9 Replies View Related

C++ :: How To Define Enumeration Inside A Structure And Use It In Other File

Mar 5, 2014

I want to define enumeration inside a structure and use it in some other file

for eg

header.h
typedef struct dummy {
typedef enum {
ZERO,
ONE,
MAX
} NUMBERS;
// some member variables
} DUMMY; // end of the structure

otherfile.cpp

in this file i want to access both enumerations(for eg) ONE as well as the type NUMBERS.

View 1 Replies View Related

C++ :: Stringstream Consecutive White Space

Oct 1, 2013

So I have a text file named test.txt on the root of my c:/drive.

I finally managed to arrays working and reading into them, but when I started looking at the data in the array I noticed that stringstream was not "grabbing" a specified space. LINES 83-88

The text file contains the following (note that there is an intentional space after the first word):

I ' m s o r 0 y 4 D a v e , 5 12 12 12 3 7 f 11 2 i d 5 8 1 c 5 n 10 t 5 7 17 2 3 h 7 2 .

I need that space to be caught in the steam, there will always be only one space after a various first word, but I need it in my array and stringstream doesn't catch it.

if you need to run it, just copy the text to a file named c:/test.txt

When you run the code, you will see after the 3rd iteration it skips the space, is there a way to change this, so I can focus on the decryption algorithm??

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <stdio.h>
#include <sstream>
#include <cctype>
bool is_number(const std::string& s){
std::string::const_iterator it = s.begin();

[Code] ...

View 13 Replies View Related

C :: Structures With Consecutive Strings (array Of Characters) As Members

Sep 24, 2014

Code:
#include<stdio.h>
#include<string.h>

typedef struct test
{
char a[5];
char b[10];
}t;

[Code] ....

In Unix (HP-UX) and Linux, the output of above program will be:

t.a=Helloworld!

Instead of the value of t.a ,i.e, "Hello" only.

Why such output? And what is the trick here to print the only value of t.a.

View 1 Replies View Related

C/C++ :: Image Overlaid Five Consecutive Times On A Live Video

Nov 30, 2012

I am trying to overlay an image on a live video.I have used alpha blending method to overlay image on the video. On overlaying the image, it gets overlayed five times rather than one as expected.

Both frame data and the image data is taken as BYTE* for overlaying and displaying it.

The image used is a bitmap image.

The data (BYTE*) of both the video and the image is overlayed and the resultant is stored back in the variable of the video and den drawn on the picture control of vc++.

The video resolution is 640x480.

The image I m overlaying is 128x128.

The IDE used is visual studio professional.The code is developed using c++.

How do I overlay the bitmap image as a single image on the live video at a specific position.

View 2 Replies View Related

C++ :: Find Greatest Difference Between Two Consecutive Elements Stored In Array

Mar 31, 2013

Develop a function that finds the greatest difference between two consecutive elements stored in an array. Develop a 9 element array of doubles to test your code. Print to the screen which two numbers have the greatest difference as well as the value of the difference. Finally include an overloaded version of the function that will work if the array is composed of integers. Include your code used to test this function.

View 8 Replies View Related

C++ :: Estimate Springtime Count Of Deer In A Park For 10 Consecutive Years

Dec 2, 2013

Write a C++ program to estimate the springtime count of deer in a park for 10 consecutive years. The population of any given year depends on the previous year's population according to the following calculation:

• If the lowest winter temperature was less than 0 degrees, the deer population drops by 15%.
• If the lowest winter temperature was between 0 degrees F and 25 degrees F (inclusive), the deer population drops by 10%.
• If the lowest winter temperature was between 26 degrees F and 30 degrees F (inclusive), the deer population doesn’t change.
• If the lowest winter temperature was between 31 degrees F and 35 degrees F (inclusive), the deer population rises by 12%.
• If the lowest winter temperature was higher than 35 degrees F, the deer population rises by 14%.

I have started with:

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
int year;
int pop1;

[Code] ....

View 3 Replies View Related







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