C++ :: How Many Elements Are Going To Be Greater Than NUM1
Jan 29, 2014
I was wondering if there was some sort of C++ equivalent for the IDL FIX function. For example, say I want to find all the elements of FLOAT ARRAY1[] that are greater than NUM1 and convert them to INT ARRAY2[].
The problem I have with writing this code myself is not knowing how many elements are going to be greater than NUM1, so I don't know how to initialize ARRAY2[?].
View 1 Replies
ADVERTISEMENT
Dec 11, 2013
im trying to write a program that finds the max in an array and divedes it by two than oututs a modfied list with all the elements greater than the max/2.
I got the first part but just not sure how to find the elements greater than the max/2 and output them correctly into the modfied list.
#include <iostream>
#include <iomanip>
using namespace std;
[Code].....
View 2 Replies
View Related
Apr 21, 2014
Write the function itob(n,s,b) that converts the integer n into a base b character representation in the string s . In particular, itob(n,s,16) formats n as a hexadecimal integer in s .
Note that it says the result is formatted into a hexadecimal integer in the string s. Here is the example provided:
Code:
void itob(int n, char s[], int b) {
static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i, sign;
if ( b < 2 || b > 36 ) {
fprintf(stderr, "EX3_5: Cannot support base %d
[Code] ....
Why does digits array hold the full alphabet when the maximum digit for a hex number is f?
View 1 Replies
View Related
Jul 24, 2014
#include<iostream>
using namespace std;
int main(){
int k,num,sum=0,GreaterNO=0;
double average;
[Code] .....
above is my program, I have received an assignment which the lecturer request us to find a series of k numbers then
-display the average
-display the total of numbers greater than the average
our lecturer request us do in 2 version, one is by using array, one is without using array, I have facing the coding problem when doing the VERSION WITHOUT USING ANY ARRAY to get the display the total numbers greater than the average, is there possible to get it?? because there are only one variable keep on looping, but the average will only get after get all the user input....?
View 8 Replies
View Related
Oct 1, 2014
Where is problem in my code, it is a flappy bird. I dont know why put me that problem when click Start on game show me on 99 line error 'maxValue' must be greater than zero. Parameter name: maxValue
I copy exception to clipboard
System.ArgumentOutOfRangeException was unhandled
HResult=-2146233086
Message='maxValue' must be greater than zero.
Parameter name: maxValue
Source=mscorlib
ParamName=maxValue
StackTrace:
[Code] .....
View 6 Replies
View Related
Feb 17, 2015
I've implemented a records system for a college assignment and everything works as intended. However upon increasing the amount of records to store in my array above 10, the program crashes upon adding a new employee and I can't work out why...
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define esize 10 /* Change max-records */
[Code] .....
View 3 Replies
View Related
Nov 5, 2014
I am new to programming in C++, and have got a project on this.
Write a C++ program that accepts three numbers from the user (All are integers):
Such as:
Enter the first mark: 3
Enter the second mark: 25
Enter the third mark: 23
The program should find and print the average of the odd numbers greater than 5 and less than 100.
View 4 Replies
View Related
Jul 27, 2014
I am facing a problem which i could not obtain the total numbers which is greater than the average value. For example:
#include <iostream>
using namespace std;
int main (){
int size , count;
double no, max, min ,total, sum , average;
[Code] ....
In this case im able to compute the average of the numbers but when it comes to capture the total of numbers which is greater than the average value, how to compile the code , because the average number is only been compute once all the value capture by the input of user is sum up.
View 19 Replies
View Related
Aug 4, 2013
I am doing my assignment that will calculate total tax amount per day and per week and finally sum those up.
One of the requirement is to filter out any number in the array that is less than 1000 to be assigned a value of zero instead of the stored value so as not to add it in the calculation. How to fulfill this requirement.
View 2 Replies
View Related
Feb 24, 2013
I was given a question in my programming class to create a program to find the factorial of any number greater than zero and to use Gosper's formula to approximate it.
Code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
double equation(int n);
int
[Code] ....
View 2 Replies
View Related
Oct 29, 2013
create a program that asks the user to input 10 integers of an array the program will add the numbers greater or equal to 10.
View 6 Replies
View Related
Oct 12, 2014
I'm trying to get unique elements from a set but it prints for each item all the rest, for example if i have 3 items in a set it will print 6 instead of 3. I use this code:
for (set<string>::iterator i = mails.begin(); i != mails.end(); ++i) {
cout << *i << endl;
}
Is there any way to print just the unique items from a set ?
The set contains:
1
2
3
But it will print
1
2
3
2
3
3
View 3 Replies
View Related
Aug 21, 2013
int sub(string &temp,int begin,int end){
if(end-begin == 0){
return temp[begin];
} else {
return sub(temp,begin+1,end) + temp[begin];}
}
I want to add all subset elements, but when i do
cout << sub(5) << endl;
it print 150....
View 8 Replies
View Related
Apr 5, 2013
I've a file that looks like this:
84484-37.96-Castor, Kathy
39050-69.68-Chandler, Ben
26183-70.84-Costello, Jerry
I have successfully read each element the id, grade and name into 3 separate array. Now i need to add a new student with an id and grade
How do i do this?
This is what I have.
int addStudent( int Iarray[], double dArray[], string sArray[], int newID,
double newGrade, string newName, int size ) {
char ready;
int index;
cout << endl;
cout << "Enter new student ID number : ";
[Code]...
View 4 Replies
View Related
Oct 27, 2014
I have a question regarding the elements of an array. Suppose I have a 3 by 3 string array (char x[3][4] ) , and I initialize all the elements to x's , the array would then look like this :
xxx
xxx
xxx
I'm curious if there will be a value if I try to access and element outside the array. As I have to write a code to determine if I have reached the end of an array. The only way I can think of is to border the entire array with o's , making it look like this :
ooooo
oxxxo
oxxxo
oxxxo
ooooo
Is there any other way to do this?
View 5 Replies
View Related
Jun 23, 2012
As far as I'm understand we have only access to .h files of elements of STL. So other words in MS VC 2010 we haven't opportunity to see exact implementation of elements of STL. Where I can find implementation of STL elements or substitute algorithm that do the same thinks like stack from stl
View 2 Replies
View Related
Mar 21, 2013
I'm writing a program with a class containing a private std::vector<bool>. I chose bool because the vector represents a 2D array (think grid) and I only need 2 states per cell. I kept it one-dimensional as this hardly complicates things.
My problem is that I don't know how to initialize the vector, i.e. fill it with 0's.
The grid's resolution is not known at compile time, so I imagine I have to set the size (and content) of the vector in the class constructor.
Here's what I have tried among several things:
Code: World::World(const u_short worldsize)
{
grid.reserve(worldsize * worldsize); // grid is the private vector; square dimensions.
std::fill(grid.begin(), grid.end(), 0);
std::cout << grid.size();
} The output is 0. Only std::vector::push_back seems to have an effect on size(), but judging by its description, it doesn't look like the right candidate to populate a vector with zeros. Correct me if I'm wrong.
Frankly I expected line 3 to set the vector's size.
View 5 Replies
View Related
Oct 19, 2013
Trying to concatenate the 1st and 2nd element from an array of chars. Then this to be used as a hex value.
so for example
specs[0]='f'
specs[1]='4'
concatenate_value=0xf4
View 9 Replies
View Related
Apr 15, 2014
Write the definition of a function reverse , whose first parameter is an array of integers and whose second parameter is the number of elements in thearray . The function reverses the elements of the array . The function does not return a value .
Code:
void reverse(int a[], int num) {
for ( int i=0; i <= num/2 ; i++){
int temp = a[i];
a[i] = a[num-i-1];
a[num-i-1] = temp;
} }
This is supposed to be the answer but I'm not quite sure why this is. I understand everything up until the actual loop. For one, shouldn't "int i" be declared outside the loop (I thought perhaps this was an error in the solutions)?
The main thing that I do not understand is the conditional statement.
Code: i<=num/2;
I don't understand why the "num/2" is necessary here. Also I can't really remember but is there a command that actually reverses an array?
View 5 Replies
View Related
Apr 9, 2013
I want to get the starting index of structure elements, whoz id are 0,1,2,3 Like in below code col_data[0] (starting id=0) col_data[3] (starting id=1) col_data[5] (starting id=2) col_data[8] (starting id=3) Code:
Code:
typedef struct gg{
int id;
int value;
}
[code]....
How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?
View 7 Replies
View Related
Apr 14, 2014
My goal is to copy only the elements of string 2 that are equal to string 1 into a new string. I tested this idea with an array of integers and it worked, but didn't work for the strings.
Code:
#include<stdio.h>
main()
{
int scan1;
char arr1[40] ;
char arr2[40] ;
char arr3[40] = {'_',.....,'_'}; /*for sake of brevity with post*/
}
[code]....
View 13 Replies
View Related
May 20, 2013
Why is it that in the STL it is standard to indicate a sequence of elements in a container by a begin iterator that points to the first element and an end iterator that points to one past the last element?
View 2 Replies
View Related
Apr 21, 2014
how to swap the first and 'mid' elements of a vector?
View 2 Replies
View Related
Dec 13, 2014
I am having some difficulties splaying this element to the root.. Considering i have this splay tree .
0
1
2
3
4
What are the steps to get it 4 to the root?
View 1 Replies
View Related
Sep 18, 2013
I'm trying to set all the elements of my array to 0 but nothing seems to be working.
.h
#ifndef ServerGroup_h
#define ServerGroup_h
class ServerGroup {
public:
ServerGroup(const int&);
[Code] .....
I want to set each element of the array in servers to 0 based on what is passed into size by numArray.
View 9 Replies
View Related
Sep 2, 2014
If I have 2 arrays, say array1 = {2, 2, 4, 5, 6} which has sorted array elements and array2 = {4, 2, 6, 2, 5} that has same elements as array1 but not in sorted condition. How can I compare that both arrays have same elements. I have written the following code which works in all conditions except when array1 has two same elements and array2 has all different elements.
counter=0;
for (i=0; i<5; i++) {
for (int j=0; j<5; j++)
if (array2[i] == array1[j]) {
counter++;
array1[j]=0;
[Code] ....
View 7 Replies
View Related