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


ADVERTISEMENT

C++ :: Write A Function That Return Maximum Value Of Array Of Doubles?

Oct 9, 2014

I'm trying to get correct answers from my exam to study for a midterm:

Write a function that returns the maximum value of an array of doubles.

Declaration:

double maximum(array[],int a_size);

So far I've done:

double maximum(array[], int a_size) {
double maxVal;
maxVal = array[0];
for(int i=1; i < size; i++) {
if(array[i] > max
maxVal=array[i]
}
return maxVal;
}

I just need any corrections.

Second, I need to write a function definition that merges two vectors containing integers, alternating elements from both vectors.

Prototype:

vector<int> merge(const vector<int> a, const vector<int> b);

This is my definition so far:

vector<int>merge(const vector<int> a, const vector<int> b){
vector<int> merged;
for(int i=0; i<a.size+b.size; i++) {
if(flag == true)
merged.push_back(a);
flag = false;
else
merged.push_back(b)
flag = true;}

I think I'm lost in the second part...

View 2 Replies View Related

C++ :: Linked List - Function Which Deletes Element If Next Element Is Bigger

Mar 10, 2014

So I have linked list and function which deletes element if next element is bigger, so my code is working but its not working with first element, in the comment I have wrote code which I would code for checking that first element, but when ever I check it is blowing up all program.

#include <iostream>
using namespace std;
struct llist {
int x;
llist *next;

[Code] .....

View 1 Replies View Related

C++ :: Function To Check For Doubles

Apr 27, 2013

Why the program continues to prompt me for a vaild number even when the correct number( a gpa) is entered. I'm not sure if the problem lies in the isDouble function or the getDouble?

*/ Determines whether the string holds a valid double. Checks if each character is digit and there is no more than 1 decimal point.
*/
bool isDouble (const string &str) {
int decimal = 0;
for (unsigned int i = 0; i < str.size(); ++i){
if ( str[i] == '.'){
decimal++;}

[Code] ....

View 1 Replies View Related

C++ :: Function That Takes Int As Argument And Doubles It?

Jan 7, 2014

Write a c++ function that takes int as an argument and doubles it.the function does not return a value.

View 5 Replies View Related

C++ :: Write Index Of Greatest Element Of Array

Oct 29, 2013

Create a program that will ask the user to input 10 integers of an array the program must write the index of the greatest element of the array

target output

input the integers

the greatest element is 5 and the index is 7

View 3 Replies View Related

C++ :: Remove Element From Array By Using Function?

Jun 2, 2013

how i can remove element from array by using function?

View 3 Replies View Related

C++ :: How To Send A Pointer To ONE Element In 2D Array To Function

Feb 2, 2015

I am trying to do this.

if (isInteger(&(tokens[i][j])) == true || isDouble(&(tokens[i][j])) == true)

Instead of sending the address of the element at row I and column j, it send the address of the entire row I. What is wrong?

View 8 Replies View Related

C++ :: Function To Initialize Double Data Array Element To 0.0

Apr 25, 2013

ok here is the question: Write a function that will initialize a double data array element to 0.0 ?

View 4 Replies View Related

C :: Why Print Entry Function Is Not Printing First Element At Phonebook

Feb 20, 2013

I have 2 function (AddEntry & PrintEntry)

I don't understand why the "PrintEntry" function doesn't print the first element at "phonebook[x].Name".

Code:
int counter=0;
void AddEntry(phone phonebook[]) {
counter++;
printf("Enter first name:
");
scanf("%s",phonebook[counter-1].Name);
printf("Enter last name:

[Code]...

Code:

int main(void) {
phone phonebook[20];
int i;
for (i=0;i<4;i++) {
AddEntry(phonebook);
PrintEntry(phonebook);
}
return 0;
}

View 3 Replies View Related

C :: Function To Return First Element Of Linked List Queue

Feb 23, 2013

I am trying to write a function to return the first element of a link list queue. I am not real sure how to implement this. I have include a copy of the struct for my Node & queue.

Code:

typedef struct event_Node {
void *data;
double arri_time;
double serv_time;
double depart_time;
double start_o_serv;

[Code]...

View 4 Replies View Related

C :: Delete Each Element In The List Which Is Same - Function Does Not Work Properly

Jan 18, 2014

Code:

struct lista* del(struct lista* p, char* path1) {
char model[MAX2];
int len;
char ch;
printf("Type model.

[Code] ..... t

This function should delete each element in the list which is the same as this one typed by user. There are no errors, but function doesn't work. It deletes something, but not this element which should.

View 5 Replies View Related

C++ :: Removing All Non-doubles From A String

May 19, 2014

I have many random strings that look something like this:

" 55.343 Char 1.3825 asdf 0.1853 500 1.1359 4.0000 1 100 4.5043"

Notices how there are ints and chars and doubles in the string.

How do I remove all non-doubles for a string like this? The chars and ints may be anywhere within the string.

View 6 Replies View Related

C :: Read Doubles From A Binary File

May 6, 2014

I use the following function to read doubles from a binary file:

Code:

int64_t read_current(FILE *input, double *current, uint64_t position, uint64_t length)
{
printf("asked for %" PRIu64" samples
",length);
printf("reading from %" PRIu64 " to %" PRIu64 "
",position,position+length);
union{
double d;
uint64_t i;
}

[code]...

As long as position+length doesn't exceed the end of the file, all is well. However, if it does, weird things start to happen. In particular, the apparent length of the file (that is, the value of "read" after the function has finished) becomes dependent on "length"). I know that "position" is never past the end of the file.

View 12 Replies View Related

C++ :: Replacing Doubles In String With Another Double

May 19, 2014

Take this string for an example, "asdf 9.000 1.232 9.00 23.1 545.3"..Is there a way to replace any of the doubles with another double? Example: Replace the first "9.000" with a "10.0". I am aware that string::replace will do the trick, but how do I make it work for arbitrary cases? By arbitrary I mean that I don't know the size of the string to be replaced, I just want to be able to replace any number with a given number.

View 1 Replies View Related

C/C++ :: Generate Random Doubles Within Certain Value Ranges?

Apr 25, 2014

I made this pthread/mutex program that makes deposits and withdrawals of random amounts. I have it working how I wish, however, I cannot figure out how to make it so that the random values are only within certain ranges. For example, let's just say I want all deposits to be random doubles between 50.00 to 100.00 and withdrawals between 25.00 to 50.00, or something similar.

#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>

[Code].....

View 3 Replies View Related

C++ :: Class Taking Integers Or Doubles

Nov 18, 2014

Ok so I have a class that takes integer fractions and I want it to be able to take doubles also depending on what the user inputs. How would I go about this? I was thinking templates ...

View 7 Replies View Related

C :: Last Element Of List Overwritten By First Element Of Another

Feb 23, 2013

I have a global list that contains smaller lists of char arrays. I have an issue where when I'm reading back the inner lists the last element of one list seems to point to first element of the next.

So my data looks like the below (values separated by commas with the pairs separated by tabs. The last pair in a line is the same as the first). When I read the first list back instead of seeing "456.678,678.98" as the last element in the list. I see "435.67,234.98" twice: at the end of the first list and start of the other. I have debugged when the list is populated and can see the correct values going in so I can't figure what's happening.

456.678,678.98 123.45,345.56 256.67,789.98 456.678,678.98
435.67,234.98 123.65,342.56 987.78,678.34 435.67,234.98

Code to fill the list:

obstacle_list = op_prg_list_create();
while (fgets(line, sizeof(line), obstaclePositions_traj_file) ) {
token = strtok(line, "
"); //Pull the string apart into tokens using the

input = op_prg_list_create();

[Code] ....

View 3 Replies View Related

C++ :: Std List - How To Get Value Of Element 2 Minus Element 1

Aug 23, 2012

I have an std list of type double.. and the list is always guaranteed to have just 2 elements. I need to get the value of element 2 minus element 1. What is the least amount of code to accomplish that?

I tried this:

Code:
list<double> dList;
dList.push_back(1.0);
dList.push_back(2.0);
list<double>::iterator iter = dList.begin();
list<double>::iterator iter2 = dList.end();
double result = *iter2 - *iter;

But this code does not work. Why not?

View 6 Replies View Related

C :: Input Validation - User To Enter Six Doubles

Dec 20, 2014

I'm trying to validate my input. I require for the user to enter six doubles and if they don't then I want them to re-enter the information. Here is my code:

Code:
while (1>0) {
printf("Please enter arguments in the order: negative mass, positive mass, initial x-position, initial y-position, initial x-velocity, initial y-velocity:
");

if ( scanf("%lf %lf %lf %lf %lf %lf",&MassMinus,&MassPlus,&Pos[0][0],&Pos[0][1],&Vel[0][0],&Vel[0][1]) != 6) {
printf("Not all numbers were assigned!

[Code] .....

At the moment it just waits if you enter less than six numbers and if you enter any more than 6 it just ignores anything after the sixth number (so pretty much does nothing). Also if I entered 1 2 a b 3 4 instead of entering six numbers it would register that as 1 2 0 0 3 4 but I want it to make the user input the numbers again. I'm also aware that "while (1>0)" isn't good programming form but I'm not really sure what to use instead?

View 11 Replies View Related

C/C++ :: Program To Find Min / Max Values Of Two Ints / Doubles And Chars

Jan 31, 2015

I'm supposed to create a program that will find the min/max values of two ints, doubles, and chars, It's not completely done but here's what I have so far.

It's giving me an Error 1 error LNK2019: unresolved external symbol "public: __thiscall MinMax<int>::MinMax<int>(int,int)" (??0?$MinMax@H@@QAE@HH@Z) referenced in function _mainC:UsersDerickDesktopCiss243Week3 Assignment2Week3 Assignment2Main.objWeek3 Assignment2

Header file
#ifndef MINMAX_H
#define MINMAX_H
#include <iostream>
using namespace std;
template <class T>
class MinMax

[Code] ....

I don't know why the site is adding in extra bits of code like /> in certain areas, it's not there when I paste it in and it's not in my code ....

View 5 Replies View Related

C++ :: Binary Search Function - Return True If Element Inputted By User Found In Array And False If Not

Nov 9, 2014

I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)

[Code] ....

Why my code does not fulfill it's purpose???

View 7 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







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