C++ :: Why Overload Constructor Not Put Values Into Arrays

Jan 7, 2014

I'm still pretty new to classes so what am i doing in this code that is wrong.

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
using namespace std;
class BunnyInfo{

[Code]...

View 6 Replies


ADVERTISEMENT

C++ :: No Constructor Could Take Source Type Or Constructor Overload Resolution Was Ambiguous

Mar 1, 2014

i am writing this bank accounts program using structures. i haven't implemented the function before that i want to check if the data is being read and printed. When i build and run the program in visual studio it gives me the following error. "No constructor could take the source type, or constructor overload resolution was ambiguous". Now whats wrong in this program?

/* Bank Accounts Program */
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>//needed to use system() function
using namespace std;
const int MAX_NUM = 50;
struct Name{

[code]....

View 1 Replies View Related

C :: Assigning Values To Arrays / Printing Arrays

Jul 1, 2014

Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.

I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {

[Code] .....

View 3 Replies View Related

C++ :: Constructor That Initializes A New Inventory Object With Values Passed As Arguments

Feb 23, 2014

Write a constructor that initializes a new inventory object with the values passed as arguments, but which also includes a reasonable default value for each parameter.

#include "stdafx.h"
#include <iostream.h>
#include <stdio.h>
#include <string.h>
class inventory {

[Code] ....

I am not trying to get my homewotk done, just to understand my errors. It complies without problem. But doesn't run.

View 2 Replies View Related

C++ :: Assigning Values To Arrays

Apr 13, 2013

Here is the code:

#include <iostream>
using namespace std;
int main(int argc, char * argv[])
{
double foo [5][5];

This is the warning:warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x...It's referring to the boldened part.

View 1 Replies View Related

C++ :: Storing Values In Arrays?

Feb 25, 2014

I'm am trying to get info from a file and put it into three arrays but it isn't working.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void sort(ifstream& infile){

[code]....

View 3 Replies View Related

C# :: ListBox Values And Arrays?

Sep 18, 2014

I'm making a simple airline reservation. I have two list boxes one has the section (A, B, C, etc) and the other rows (1, 2, 3, etc). I used two different arrays to put the values into the list box via form unload. The problem I can't seem to figure out is how can I update these seats and inform the user if a seat is taken or not. Lets say a customer takes A-1 (only seat taken). If I try to add someone else there it will inform me that seat is taken and to select another one. If all the seats are taken it'll tell me to put customer into the waiting list.

Also one more thing is that each row has 3 seats, so A-1, A-2, A-3 for example. If say A-1, A-2 are taken when I push a button show remain seats it should show A-3 only. I have a lot od struggle using arrays.

View 3 Replies View Related

C/C++ :: Storing Values In Arrays Using For Loop

Nov 18, 2013

I am trying to create a program that will give me an value for a chosen from the user array ut I believe the program I've made does not recognize the values of the previous arrays. (Here is my program):

#include<stdio.h>
int main() {
int n;
int i;
int j;
float c;
float a[10000];

[Code] ....

There must be problem cause every value I give n(only for n=1 the answer is correct) the result is "a[n] is -inf"

View 1 Replies View Related

C++ :: Processing Structured Arrays - Too Many Initializer Values

Apr 22, 2013

I working on an assignment that processes an array of structs. In the main function I am attempting to declare an array of Author structures with 3 elements. It is supposed to be initialized to set all of the string fields (the names and book titles) to "NONE", and the double fields (the prices) to zero. This is supposed to be done in one statement, not using loops. Here is what I have.

struct BookInfo struct Author
{ {
string title; string authorName;
double price; BookInfo books[SIZE] //SIZE = 3
}; };

//prototype for function to print the content of array on screen
void showInfo(Author a[], int size);

[Code] .....

I was under the impression that an array can only hold the values of one data type. So doubles and strings in the same array doesn't make sense to me. However, that's the example my teacher drew up. The error keeps telling me that there are too many initializer values.

View 4 Replies View Related

C/C++ :: Function Not Returning Values - Structs In Arrays

Feb 25, 2015

I wrote this code for a homework assignment, everything runs fine but the function void percent_votes (line 66) isn't calculating properly, it outputs 0.00 for each value. I have tried everything I can think of to try and make it work.

Here is the assignment: Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election.

Here is the code I have written:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

[Code].....

View 4 Replies View Related

C/C++ :: 2D Dynamic Arrays - How To Create And Give Values

Apr 23, 2014

I cant get with part of it is wrong, i want to sum every row, too.

// Color Number.cpp : Defines the entry point for the console application.
//  
#include "stdafx.h"
#include<conio.h>
#include<iostream>

[Code].....

View 1 Replies View Related

C :: Read Specific Values From A File And Store Them In Arrays

Apr 14, 2013

What i try to do is to write a code which reads some specific values from a file and stores them in an array. My File looks like this

Code:

XFOIL Version 6.96
Calculated polar for: Myfoil
1 1 Reynolds number fixed Mach number fixed
xtrf = 1.000 (top) 1.000 (bottom)
Mach = 0.000 Re = 0.200 e 6 Ncrit = 4.000
}

[code]...

View 11 Replies View Related

C++ :: Tree Arrays Of Same Even Lengths And Adds Values At Odd Indexes

Oct 22, 2013

I am trying a program with that takes tree arrays of same even lengths and adds the values at odd indexes and save at even index of 3rd array and voice versa........

what will be the logic i have tried it a lot of time not worked................

View 3 Replies View Related

C/C++ :: Transfer Array Values To Positive And Negative Arrays?

Oct 21, 2014

I have a problem with my assignment. I would like to ask how to transfer positive and negative values from array temperature to arrays positive and negative?

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n=0, d=0, temperature[20], sum;
int positive[], negative[];
float avg;

[code]....

View 5 Replies View Related

C/C++ :: How To Assign Values From Text File To Structure Of Arrays

Sep 5, 2014

have to do an election program in C.

There are 7 candidates and 365 votes in total. I need to do this using an array of structures. I need to read from a text file each of the names of the candidate and the number of votes they get. At the end i need to output the winner of the election.

Here is a sample of my code so far

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct candidates {
char name[20];
int votes;

[code]....

Here is a sample of my text file:

Robert Bloom
John Brown
Michelle Dawn
Michael Hall
Sean O’Rielly
Arthur Smith
Carl White

1 2 4 5 1 2 3 4 4 1 2 3 7 4 4 5 3 7 7 7 7 7 7 7 7 7

Each candidate gets +1 vote for their number electionCandidate[0] for each one he gets one vote and so on for the rest. 365 voters in total.

I was able to input the name for each Candidate from the text file. Now the problem is putting each vote to the corresponding candidate. Also any vote that is above 7 is a spoilt vote which i am trying to count in the above code. The code compiles but it crashes.

I am using while(!feof) but it seems that its not working or this is not the correct way.

View 6 Replies View Related

C/C++ :: Comparing Element Values In Dynamic Parallel Arrays

Oct 30, 2014

I've been working on an assignment that deals with newspaper advertisements. I have two arrays:

categoryCode (the code for the advertisement's category such as pets, cars, etc) and
numWords (number of words in the ad).

The arrays are dynamic.

My assignment has the category listed each time there is an ad associated with it and then its number of words for that ad. If this were a real-world issue I would want my output to list each category only once despite how many ads were in it, list how many individual ads are in the category, and its total number of words for the ads in that category. When using parallel arrays, is there a way to do this?

Let's say I have categoryCode with three elements {5, 5, 7} and numWords {10, 12, 15}.

How would I make the numWords add together only when the categoryCode values are the same?

I would want the output to print:
Category 5 Ads 2 Words 22
Category 7 Ads 1 Words 15

rather than how my instructor is having us do it like this:
Category 5 Words 10
Category 5 Words 12
Category 7 Words 15

I think I'm getting hung up because my mind is confusing the element's location in the array with the element's actual value and I'm probably making this harder than it should be. How would I compare the categoryCode values in a dynamic array? If it were a fixed size I think I could just compare categoryCode[0] to categoryCode[1] and so on, right? But in this case I'm not sure how I would go about that.

View 6 Replies View Related

C++ :: Values Are Changing When Passing Arrays And Array Sizes?

Feb 28, 2014

I'm working on a homework assignment that asks me to roll two die a user given number of times, find the roll sums, and a few other things. I'm working on it one module at a time and I'm running into two big problems so far.

The first problem is that my int variable rolls changes to a number within the random number generator range of numbers after I run rolldie. I got around this by making a const equal to the user entered value of rolls just so that I could continue developing the program.

My second problem is that the values of the arrays resultsOne[] and resultsTwo[] are changed after running findsum(). Why this is happening and I even tried passing them as const, but that changed nothing. We just started learning about passing arrays to functions, so there might be something big that I'm missing.

Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void rolldie(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo);
void findsum(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo, int tossSums[], int sizeOftossSums);

[Code] ....

View 8 Replies View Related

Visual C++ :: Arrays - Solve Equation Using All Volume Values

Dec 22, 2012

I am using matlab R2o11 in which the programming medium is c++. I am having these variables=

T=373 t0 376
V=0.09 to 1
P=T/V

I just need a result showing ... First it should take T=373 and solve the equation using all volume values. Then it takes another temperature and do the same.

View 4 Replies View Related

C :: Function That Merge Content Of Two Sorted Arrays Of Double Type Values

Nov 4, 2013

I need to write a function that will merge the content of two sorted arrays of type double values. The function should not assume that both its input parameter arrays are the same length.

Here is my program so far - I know there is alot of errors and mistakes:

Code:

#include<stdio.h>
void merge(int firstArray[],int secondArray[],int size) {
int mergedArray[size],i=0,j=0,k=0;
while(i<size||j<size) {
if(i==size) {

[Code]...

View 2 Replies View Related

C/C++ :: Madd Libs Game - How To Store Inputted Strings Or Values To Arrays

Nov 11, 2014

My assignment is writing Madd Libs game. I still do not understand how to store inputted strings or values to arrays. I need explanation of collecting inputted data to arrays.

#include "stdafx.h"
#include<stdio.h>
//#include<string.h>
int main(void) {
char string[37] = {''};
char adjective1[15];

[Code] ....

View 14 Replies View Related

C++ :: Calling Constructor From Constructor Set Pointer To Null

Jan 25, 2014

VS 2012 / Windows 7 64 bit

class
class myclass {
public:
myclass(){/*stuff here*/}
myclass(int* p) {MyPointer = p; myclass()}

[Code] ....

it works until the myclass(int* p) calls myclass()

then the MyPointer will become CCCCCCCC (NULL value)!

is there a way to stop the second constructor from resetting the pointer value to null?

View 3 Replies View Related

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

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

C++ :: How To Overload Operator Twice

Jul 10, 2014

Here's my question. I'm coding a basic Linked List class (for the purpose of understanding and having fun, I know about STL), LList.

I have overloaded the [] operator so it returns the data of the index-th node in the list, for example, if I code

LList x;
....
cout<<x[5];

it prints the data of the 5th node in the list (for fun I decided to index from 1 to infinity).

My question: Now I want to be able to assign the value to the index-th node data, using [] and =, for example, I want to be able to write:

LList x;
.....
x[5] = 121;

How can I do that?

View 3 Replies View Related

C++ :: How To Able To Overload A Multiplication Operator

Apr 24, 2014

How would i be able to overload a multiplication operator that if, in the main example(0, 5, 0) * example (0, 5, 0) is given, it gives me 25?

View 1 Replies View Related

C++ :: Overload With Template Function

Nov 15, 2013

I am a beginner, got confused about:

template<typename T> int compare(T &a,T &b);
int compare(const char *a,const char *b);
char ch_arr1[6]="world",ch_arr2[6]="hello";
compare(ch_arr1,ch_arr2);

After running the code above,we got to know the non-template function is called. What I know is that the array arguments ch_arr1,ch_arr2 will not be converted to char * because the parameters are references in the template functions.

ch_arr1,ch_arr2 need to be converted to const char * if compare(const char *a,const char *b) were called.

I just wanna know what exactly happened behind that? and why?

View 15 Replies View Related

C++ ::  How To Overload Variables In Derived Classes

Apr 6, 2013

Is it possible to overload a variable in a derived class? Example:

struct Circle
{
int radius() const { return r; }
private:
int r;
}
struct Smiley : Circle
{
// inherits the function int radius() const, but doesn't return Smiley::r
private:
int r;
}

View 7 Replies View Related







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