C++ :: Stock Market Program - Sorting With Vectors
Sep 29, 2013
I'm writing a program of a stock market where i read from a file and sort with symbols and percent gain/loss. I have completed sorting with symbols but having trouble establishing the percent gain loss. First i designed and implemented the stock object. call the class stockType. main components of a stock are the stock symbol, stock price and number of shares. Second we have to create a list of stock objects. call the class to implement a list of stock objects stockListType. To store the list of stocks, i declared a vector and called the component type of this vector stockType. Because the company requires me to produce the list ordered by percent gain/loss, i need to sort the stock list by this component.
However, i'm not to physically sort the list by component percent gain/loss; instead i should provide a logic ordering with respect to this component. To do so i added a data member, a vector to hold the indices of the stock list ordered by the component percent gain/loss and i called this array indexByGain. I am going to use the array indexByGain to print the list. The elements of the array indexByGain will tell which component of the stock list to print next. I have trouble going about how to implement the function sortStockGain(). Below is my entire code and the txt file. I have sort symbols working but dont know how to implement the sort by gain.
Write a C program that calculates the final value of an investment made in a TSX Market Linked GIC.
Specification
The return on this type of GIC (Guaranteed Investment Certificate) is based on the initial investment, the number of years (1, 2 or 3), a minimum return rate, a maximum return rate, a participation rate, the values of the TSX (Toronto Stock Exchange) index at specified intervals during the years, and the type of averaging of these values. The final investment value can only be calculated once all the TSX values are known.
If averaging is not used the TSX rate is determined from the opening and closing values only. If averaging is used the TSX rate is determined by calculating the TSX average at 6 monthly intervals, then is based on this average relative to the opening value. The TSX rate is then multiplied by the participation rate. If this new rate is below the minimum rate, then the minimum rate is used, and if it is above the maximum rate, then the maximum rate is used. Rates are printed to 2 decimal places, and the final investment is rounded down, and formatted using commas.
Only round down for the final investment. If the TSX rate is negative do not print the line for rate adjusted for participation. Assume that the final investment is less than one million dollars. (Hint: if you need to print leading zeros in a number, use the %0m.n format: example - the format specifier %06.2f prints 4.56 as 004.56)
Example 1: See below; averaging is not used, so TSX rate = (107-100)/100 = 7%. After using a participation rate of 80%, get 5.6% (which is between min & max rates).
Example 2: See below; averaging is used over 5 values to get a rate of 68% which equals 54.4% due to participation. This is more than the max rate, so the max rate is used.
The GIC calculator must use the following layout exactly.
+------------------------------------+ | TSX MARKET LINKED GIC CALCULATOR | +------------------------------------+ Enter initial investment : 1000.00 Enter number of years [1,2,3] : 3 Enter minimum and maximum rates [%] : 1 20 Enter participation rate [%] : 80 Enter if averaging used [1=yes,0=no]: 0 Enter open and close values : 100 107
+------------------------------------+ | TSX MARKET LINKED GIC CALCULATOR | +------------------------------------+ Enter initial investment : 2000.00 Enter number of years [1,2,3] : 2 Enter minimum and maximum rates [%] : 1 20 Enter participation rate [%] : 80 Enter if averaging used [1=yes,0=no]: 1 Enter 5 TSX values : 200 190 320 430 540
Final investment . . . . . . . . . . $ 2,040.00 i wrote something like
Code: #include <stdio.h> int main (void) { int years, minimum, maximum, partrate, x, open, close, tsxvalue; float investment, tsxrate, y, finalinvestment, maxrate, minrate; printf("+------------------------------------+
[Code] ....
I don't know what the exact calculation should be here now to get the rest....so I'm stuck here
Okay, so my assignment for my C class is to generate a program that will allow the user to enter data for a stock and calculate the amount of stocks that ended up being positive, negative, and neutral.I tried to do this using one stock, here is my code;
I have two vectors of float that I need to sort in reverse order. reverse() seems to work for one of them, but not the other. I have toggled between sort() and reverse(). for one vector, the expected behavior is seen and the order reverses. For the other, there is no change in order.
This is very simple code, so it's hard to imagine what is going wrong.
You can see that the order of the first vector did not change. Am I right in suspecting that the numbers are too similar for what ever method reverse() uses to determine the difference between values?
I have a vector which contains vectors containing 7 integers each. I'd like to sort these vectors based on the value of the first integer (int IOT), in ascending order. I know this type of question can be found everywhere, but I'm lost as to why this doesn't compile.
#include <fstream> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <stdio.h> #include <math.h> #include <windows.h> using namespace std; class orders { public: int IOT; // Incoming Order Time
Basically I need to make a program which asks for a business name and then keeps asking for more until user doesn't want to. Once more than 1 business is enter it should display the business and sort it alphabetically and keep displaying them each time another is added. I am lost on how to store the added business, sorting it and displaying the list.
Here is what I have so far.
#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main () { string business_name; char selection;
I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two separate vectors. After an unknown amount of data has been entered, and the end-of-file has been reached, I have to display the highest temperature and the time(s) it occured (bear in mind that the highest temperature may be recorded more than once). The output of that part should be as follows:
Highest temperature: 51 Recorded at time(s): 22:45 2:27
Something like that. The time should also be converted to hours and minutes. To the point: I've done some research on bubble sorting, but they only use it for arrays.
I would like to make a simple program that will go to a online vendor's website to check for stock. I figure that the best way of doing this is to make the program download the webpage's HTML source code then search for the area where the stock availability is.
For example, on this webpage. I could make the program search between
<p class="stockstatus"> and </span></p> for Sold Out to determine whether the item is in stock or not.
I have a couple of questions. First of all, is this the most viable way to go about checking whether an item is in stock? Second, how should I go about coding it?
Let's say we have entities like lines and circles. And each entity can have a pen attached. And a pen is a color and line width. All entities needs to be manipulated through a operations interface. All entities added to the program needs to be added through using a factory pattern.
So we end up something like (pseudo code)
class Line // for immutable objects { .. .. } class MutableLine extends Line //for mutable lines { } MutableLine line=factory->newLine(20,20,50,50); // Create a new line entity
[code]....
So, essentially I want no code to be able to operate directory on entities, unless during creation of the object (color, layer, line width etc...) so I am planning to create Mutable versions of all entities besides the immutable versions.
When requested for selected entities or all entities, I am planning to return a list of immutable objects and in fact I am planning to return a new copy so it's not possible to operate on anything directly.
The reason is that I am planning to create different storage backends swell, so I can operate on entities in a database, or shared memory... stuff like that. At least to hide the internals and provide a stable API.
My questions are:
How can I make sure that people don't do 'tricks' casts for example to a mutable version to change objects directly?
void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA { vsFA[n] [m]= simTime().dbl(); OR vsFA[n].push_back(simTime().dbl()); }
I have a local student and international student class inherit from student class. read and print are virtual functions. After i have set all the member variables when i wan to print out all the student information, my program crashes.
Code: int main() { clsUniversityProgram objProgram[3]; for (int x = 0; x < 3; x++)
This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.
The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.
So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:
[1,1] [1,2] . . . [10,10]
This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.
I have been learning c++ for about 1 month. So my problem is that suppose i have array[6]={10,-1,3,54,2,12}
I want to fill new array with {1,4,2,0,5,3}
because -1 is the lowest and its index is 1 2 is the lowest and its index is 4 3 is the lowest and its index is 2 10 is the lowest and its index is 0 12is the lowest and its index is 5 54 is the lowest and its index is 3
I want to sort from lowest to highest but using the index value. Here is what i have but the output i get is {1,4,2,4,5,5} 1,4,2 is right but then its wrong.
#include <iostream> using namespace std; void swap(int& v1, int& v2); int main() { const int size = 6; int arry[6]={10,-1,3,54,2,12}; int sortedArry[6];
I am a beginner at C++, the output is pretty self explanatory. I'm trying to make a number sorting program with other features, but the numbers are all wrong.
Code: #include <iostream> #include <iomanip> #include <fstream> using namespace std;
I have to write a program that sorts numbers from least to greatest. The way that it has to sort them is:
1) The program assigns the first number to be a minimum 2) If the next number is less than the minimum is now that number and they switch places. (We keep on looking if the number next to it is not smaller) 3) The program also gets the index of the minimum number 4) We keep on going until it is in order.
// Sort.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include <iostream> #include <vector> using namespace std; void Sort(vector<int>&input); int _tmain(int argc, _TCHAR* argv[]){ vector <int> input;
i want to write an array sorting program that works with recursive function.but i can not do it.
my algorithm
Recursive find the min value find the min value and save it find the min value and save it and remove it from loop put the rest in loop again find the min value again .. ...
i didnt write the function because i dont know how will it work
Code:
#include<stdio.h> #include<stdlib.h> #define s 5 void main() { int a[s]={25,3,2,4,1},c[s]; // c[s] for new sorting int i,ek,j; //ek = min
I was trying to implement sorting in a linked list. However, when i run the sortList() function the program abruptly terminates. Here's the complete code:
Code: /* * { * SingleLinkedList.c * * Created on: 28-Nov-2014
I'm currently trying to code a sorting algorithm program.
let's asume I have a string given: aa, aaa, bbb, bas, zya!
I first of all want to split the given string on commas and '!' tells the program the string ends here and is no part of the last word. lower and upper case is not important at the moment. trying to implement everything with standard libary
output should be like that ofc: aa aaa bas bbb zya
I already looked into the bubble sort algorithm and I think it benefits my needs. Just wanted to know how I should start out with the string split.
I've got this sorting program that uses variables from another class but I'm not sure why its not recognizing it. I'm getting an error length and list not declared in this scope.
#include <iostream> #include "arrayListType.h" using namespace std; template<class elemType> class orderedArrayListType: public arrayListType<elemType> {
I am having an issue with my sort function. This is one part of the Hash table program. The main issue is that I am trying to sort the pointer table after all of the values have been entered. The ptr_sort function is not a class function and so I am therefore unable to use the class variables psize and pTable. Is there another way I should be trying this? it is a Vector should I use the sort() function from the vector class in STL?
I want to add 2 vectors to print out so that there on the same line. What I am trying to make is an inventory system that will use 2 vectors to keep the pounds of the item and list the 2 vectors on one line.
(I am using Microsoft Visual C++ 2010 Express)
Like this:
0. empty 0 1. empty 0 2. empty 0
etc...
Right now it looks like this:
0. empty 0. 0
The code:
#include "stdafx.h" #include <iostream> #include <vector> #include <string> #include <fstream> #include <cmath> using namespace std; int main() { vector<string> inv;
I have a vector I want to add book titles to, then i want to print my updated vector. This is best I have come up with but the program fails at the getline line. why?
string book; cout << "Enter book to add: "<< endl; getline(cin, book); books.push_back(book); for(int i = 0; i < books.size(); ++i) { cout << i+1 << ". " << books[i] << endl; }