This is another homework problem. I thought it was easier, and I wouldn't need help, but I keep getting a segmentation fault when running the program. The assignment is to use a recursive function to output the amount of candybars we can buy with a user-inputted amount of money. Each candybar costs $1, and each candybar gives a coupon. 7 coupons can be redeemed for an additional candybar. The example he gave us is: "For example, if we have $20 dollars then we can initially buy 20 candy bars. This gives us 20 coupons. We can redeem 14 coupons for …

Member Avatar
Member Avatar
+0 forum 12

This is homework. I am not asking for someone to write this code for me, just to help me understand how to solve my problem. I have to take two lists or integers inputted by the user, sorted in ascending order and combine them using pass-by-reference to return a pointer to the head of a new list that contains all the values from the first list, now sorted in ascending order together. Ex: List A contains 3,5,6,10; List B contains 1,4,5,7,10,11. The resultant list should output 1,3,4,5,5,6,7,10,10,11. I am very new at lists, and don't quite understand them fully but …

Member Avatar
Member Avatar
+0 forum 13

This may be a simple fix, but I have a class for a program that contains some member functions that manipulate a vector. The vector is a private member variable, and is filled from an array using a constructor. When I try to access the member functions to manipulate the vector, the vector is empty. I have tested the constructor and member functions separately and they work fine on their own. Here is the code: class and #include directives [CODE]#include <iostream> #include <vector> using namespace std; class NumberSet { public: void add (int A); //adds an element to the set …

Member Avatar
Member Avatar
+0 forum 1

When writing a program that uses separate compilation (I have a header file, a .cpp file that declares all the member functions of the class in thee .h file, and an application file). I used a constructor to pass the contents of a dynamic array to a vector, but it is not passing properly. Here is the constructor: (everything is declared properly, the constructor is a member of the class NumberSet) [CODE]NumberSet::NumberSet(int array1[]) { for (int e=0; e < array_size_horizontal; e++) { v1.push_back(array1[e]); } }[/CODE] The constructor is supposed to be used during the main function, but I can't get …

Member Avatar
Member Avatar
+0 forum 17

Okay, we had an assignment in computer class that I have been working on for awhile but what I've got so far isn't working. It seems that it may be a compiler issue, but since I can't get to a linux compiler (what the program will be evaluated on), and since I suspect I have some other errors, I figured I would ask it here. I am not asking for you to rewrite the program, but I would like help as soon as possible, as it is due shortly. Here's the problem: 1. Define a class called NumberSet that will …

Member Avatar
Member Avatar
+0 forum 2

The first day of class today we had an (optional) diagnostic programming assignment. The problem is: to take an input file with a sentence in it, and make all letters except the first one lowercase, make the first letter uppercase, and remove any extra spaces and line breaks. After working for awhile, and looking around for help, I have a basic idea of what I have to do, but so far it doesn't seem to be working. [CODE] #include <iostream> #include <fstream> #include <cstdlib> #include <cctype> #include <string> using namespace std; ifstream in_stream; string line; char file_name_input[21]; char firstchar; int …

Member Avatar
Member Avatar
+0 forum 11

Hello, I need to take a file filled with numbers and input them into a two-dimensional array. The file would look like: 3 6 3.9 4.5 2.1 1.0 2.4 4.3 3.1 4.2 5.1 6.2 1.0 2.7 1.2 2.3 3.1 4.2 5.2 6.4 where the first two numbers are the vertical and horizontal dimensions of the array. I have to do this by using pointer and new. Now, I've gotten it partly done, but I've gotten stuck reading the numbers into the array. Each row is the test scores for a student, so each horizontal array is a different student. It …

Member Avatar
Member Avatar
+0 forum 10

The End.