C++ :: Finding Sum Of Two Fractions - Return Array In Function?
Jul 30, 2013
I am making a function that finds the sum of two fractions(fractions are arrays of 2 elements). how would I return an array?
int addFrac(int f1[2], int f2[2]){
int num1 = f1[0]; // numerator of fraction 1
int den1 = f1[1]; // denominator of fractions 1
[Code] ......
View 2 Replies
ADVERTISEMENT
Nov 27, 2013
How to find the size of an array in called function? When we pass the array a argument to function definition we will be having base address of array, so my understanding is that we will not get the size of an array? but is there any hacking for this to find size of array other than passing as size an argument to this called function?
View 3 Replies
View Related
Apr 2, 2014
The problem is how to return an array of integer from a function?
I'm writing a C program code to return an array of integers ( grades of students ) to the main function!
View 9 Replies
View Related
Apr 23, 2014
I passed an array from a function from a class and i am using the object of that class in other file but when i pass it the values of that array are coming ssome junk values (i think) i ll show u the usage :
// randomno.cpp : Defines the entry point for the console application.//
//#include "stdafx.h"
//#include<iostream>
#include<ctime>
using namespace std;
class randomnogen {
[Code] ....
Then I used it in my main file like this:
int* Q_Rand = &o_random_gen.generate();
o_SciTech.showQuestion(Q_Rand[i],main_quesfname);
The value of Q_Rand comes out to be some very large value sometimes negative sometimes positive (i.e a junk )....
View 12 Replies
View Related
Oct 2, 2013
I have an object that I use to store data. Two of its members are dynamic arrays. When passed (by reference) to a function used to fill the arrays with data, everything works fine. However, only the 0th index of the arrays remain populated after the function call.
parameters.cpp // class reference
#ifndef parameters_H
#define parameters_H
using namespace std;
class parameters {
public:
double k;
double c;
double a;
double vci;// Cut-in velocity
[Code] .....
View 19 Replies
View Related
Mar 8, 2014
// I believe my loop for the functions work but the values are not returning !
// Acoustic data
#include <iostream>
#include <fstream>
using namespace std;
double low( double []);
double high( double []);
void readArrayr( double [], double , double);
[Code] .....
View 6 Replies
View Related
Sep 17, 2014
How to pass my array to the function and return it as a sorted vector. I'm kind of lost with the functions part.
Problem: Write a program that performs a sorting routine as discussed in class. Create an array of 10 integers (e.g., 63, 42, 27, 111, 55, 14, 66, 9, 75, 87). Pass this array to a separate function that sorts the integers and returns a vector containing the sorted integers. Use either the SELECTIONSORT algorithm or the INSERTIONSORT.
Code so far:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
[Code]...
View 2 Replies
View Related
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
Mar 29, 2013
I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?
Code:
#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}
[code]....
View 4 Replies
View Related
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
Dec 12, 2014
i recently started programming. i mean I've been exposed to programming for the first time about a week ago. I've been following the tutorial here and playing around with my own code. For some reason, this code works while receiving decimals but not fractions.
Code:
#include <stdio.h>
int main()
{
float kd;
float kd_2;
printf("Please enter your k/d
");
scanf("%f", &kd );
}
[code]....
View 7 Replies
View Related
Oct 24, 2013
I need to write a program that can calculate fractions.
View 2 Replies
View Related
Jul 12, 2012
I have to write a function
struct rNumber add(rNumber a ,rNumber b);
which adds two rational numbers in following representation :
rNumber := s*(n/d)* 2^e
struct rNumber{
_byte_t s; // sign (do not consider for this question)
uint n; //numerator
uint d;// denominator
short e;//exponent
}
If the exponents of both numbers are not equal, then they have to be made equal in order to add them. This can be made in 4 ways : increase or decrease the n or d of both numbers.
But if we decrease the denominator of a number (a.d =1) by shifting it for example 1 bit to the right, we get 0 which leads to INFINITY for the fraction. In another case decreasing the numerator would lead the n to be 0 which meanse the whole fraction is then 0.
According to this, in worst case, all 4 cases has to be checked for the right result.
So far the UNDERFLOW of n or d is considered. If we try to increase the value of n or d, then OVERFLOW may also occur.
The very first, intuitive solution would be iteratively increase/decrease one of the terms and to check if the change leads to ZERO or INFINITY.
View 5 Replies
View Related
Mar 18, 2014
Ii need an output like this...
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <ctype.h>
#include <locale>
using namespace std;
int EquationNum (int Num1, int Den1, int Num2, int Den2);
[Code] ....
View 9 Replies
View Related
Feb 17, 2013
I'm looking for a library that handles rational, irrational and trascendental numbers and calculates the exact results without approximating values. For example, if I want to calculate:
a = pi;
b = 3;
c = 2;
I want this library to return the result in this way:
sqrt(b*c)*a == sqrt(6)*pi
instead of
sqrt(b*c)*a == 7.6952989
In case it matters, I'm working on Ubuntu and I compile with g++.
I'm pretty sure a library like that exists because it's too useful, I researched it but couldn't find anything.
View 4 Replies
View Related
Jul 16, 2014
I was trying 2 write a program that would calculate the sum notation of 1/(i^2) with the starting number to be 1 and goes up to the nth term. For instance if the user inputed 3 then the sum would look like 1+1/4+1/9. I somehow made a code but it gets weird numbers which some include negative numbers... when I input a number that is above 5.
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
int n;
register int i=1;
float b;//For part 1
[Code] ....
For some reason I can't edit printf("%f",/>/>; when I post it as the topic so ignore that part cuz Ik its supposed to be written as printf("%f",/>;
View 6 Replies
View Related
Feb 12, 2014
I'm trying to pass 2 arrays into a void funtion, and return values to one function.
this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.
#include <iostream>
using namespace std;
void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize);
int main() {
int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189};
int numberCount[8] = { 0 };
[code]...
The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.
View 6 Replies
View Related
Aug 1, 2014
I'm working on a Fraction Class assignment where I'm supposed to provide conversion operators to allow Fraction objects to be used in expressions containing float data values. The way I have it now, I'm getting an error that says operator float(const Fraction &) must contain 'void', which makes no sense to me. Lines 155 - 173.
// Fractions CLASS
// Source: Fraction2012.cpp
// Author: Warren H. Knox, Jr.
// Date: 11/8/2012
#include <iostream>
#include <cstdlib>
using namespace std;
class Fraction {
[Code] ....
View 9 Replies
View Related
Jul 25, 2013
I'm trying to compare 2 fractions using operator overloading. The program crashes when this is called;
this is definition:
bool operator == (const Fraction& f1, Fraction& f2) {
if (f1==f2)return true;
else return false;
}
this is my calling in the main:
Fraction f1, f2;
cout<<"Enter in the format: 2/4 or 4/9
";
cout << "enter first fraction: ";
f1.Input();
cout << "enter second fraction: ";
f2.Input();
Fraction result:
result = (f1 == f2);//i think problem lies here.
result.Show();
and this is the prototype of the operator:
friend bool operator == (const Fraction& f1, Fraction& f2);
View 7 Replies
View Related
Jun 9, 2013
The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.
right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.
Code:
#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {
[Code].....
View 4 Replies
View Related
May 8, 2014
What is the syntax to find the maximum of a function over the interval a≤x≤b starting at a with a step size of Δx ?
View 1 Replies
View Related
Apr 14, 2013
How can i solve a problem of sin(x) without using any math.h and only using my own declared function.
#include <stdio.h>
int fact (int a) {
int i;
int k = 1;
for (i=1;i<=a;i++)
[Code] ....
View 3 Replies
View Related
Feb 10, 2013
My code compiles fine but it doesn't seem to want to calculate the max integer. It calculates min and average fine but I'm not seeing what is wrong with my code. The max integer keeps coming out wrong.
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <cstdlib>
#include <algorithm>
using std::swap;
[Code] ....
View 1 Replies
View Related
Sep 12, 2013
I have written a delete node function to delete a node in a linked list by the index number. Here is the code:
Code:
void delete_node(struct node **start,int index_no)
{ int counter=0;
struct node *current=*start, *prev=NULL;//Current holds start and prev holds previous node of current
while(current->next!=NULL)
[Code]....
note that I know if the head node turns out to be the indexed position, there is no way to delete that node in the current coding. But please after correcting the present node add that part of the code separately.
View 5 Replies
View Related
Nov 23, 2013
I would like to see what functions the following header file has:
#include <tf/LinearMath/Transform.h>
Any website that has all the c++ libraries and where to find the functions that come with this?
View 4 Replies
View Related
Jul 9, 2014
I want to search a 2D array to see if it contains a certain value x. I can come up with three different ways to do this. Provided I have:
const int Rows = 40;
const int Columns = 30;
int SampleData[Rows][Columns] = { ... }
Is there any real difference (in terms of performance etc.) between these, or are there an even better solution?
Solution 1:
for(unsigned row = 0; row < Rows; ++row) {
for(unsigned col = 0; col < Columns; ++col) {
if(SampleData[row][col] == x) {
// found
} } }
Solution 2:
int* data = &SampleData[0][0];
if(find(data, data + Rows * Columns, x) != data + Rows * Columns) {
// found
}
Solution 3:
int* data = &SampleData[0][0];
for(unsigned i = 0; i < Rows * Columns; ++i) {
if(*data++ == x) {
// found
} }
View 1 Replies
View Related