The 4th deliverable is to create the program the makes the buy recommendation. It uses the class Stock to store and retrieve the stock information. I need to make this program compatible with my stocks class.
Program I need to change:
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <string>
#include <stdlib.h>
using namespace std;
// read the data file, store in arrays
int openDatafile(ifstream&,string [], float[], float[],
int[]); // opens the data file
void readData(ifstream &, string[], float[], float[], int[],
const int MAX, int&); // reads in the information from data
file
void getSymbol(ifstream&, string [], int); // reads in the
symbol
void getCurrent(ifstream&, float[], int); // reads in the
current price of the stock
void getBought(ifstream&, float[], int); // reads in the bought
price of the stock
void getShares(ifstream&, int[], int); // reads in the number
of shares owned
void outputResults(string[], float[], float[], int[], int&); //
output the possible buy stocks for user
int main () {
ifstream ifs;
const int MAX= 100; // 100 is max number of stocks that will be
read in from file
string s [MAX]; // gets the stock symbols
float c [MAX], b [MAX]; // gets the current price; gets the bought
price
int shares [MAX]; // gets the number of shares owned
openDatafile (ifs, s, c, b, shares);
int numberRead = 0;
readData(ifs, s, c, b, shares, MAX, numberRead);
outputResults (s, c, b,shares, numberRead);
return 0;
}
/*********************************************************************/
/* */
/* Function name: openDataFile */
/* Description: opens the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
//gets the user to type in the file name
int openDatafile (ifstream &ifs, string s[], float c[],
float b[], int shares[]) {
int i;
ifs.open("stocks.dat"); // opens data file
if(ifs.fail()){
cout << "Error opening file: stocks.dat" << endl; //
throws an error message if fails
exit (1);
}
}
/*********************************************************************/
/* */
/* Function name: readData */
/* Description: gets the name of the data file from user */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// reads in the data from the file
void readData(ifstream &ifs, string s[], float c[], float b[], int shares[], const int MAX, int& i){
for (; i<MAX && !ifs.eof(); i++) { // creates the loop for going through file
getSymbol(ifs, s, i);
getCurrent(ifs, c, i);
getBought(ifs, b, i);
getShares(ifs, shares, i);
}
}
/*********************************************************************/
/* */
/* Function name: getSymbol *
/* Description: read the symbol from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses data file to get symbol
void getSymbol(ifstream &ifs, string s[], int i) {
ifs >> s[i]; // reads in the number of shares from the data file
}
/*********************************************************************/
/* */
/* Function name: getCurrent */
/* Description: read the current price from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses data file to get the current prices of the stock
void getCurrent(ifstream& ifs, float c[], int i) {
ifs >> c[i]; // reads in the current price of the stock
}
/*********************************************************************/
/* */
/* Function name: getBought */
/* Description: read the bought price from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses the file to get the bought prices of the stock
void getBought (ifstream& ifs, float b[], int i) {
ifs >> b[i]; // reads in the bought price of the stock
}
/*********************************************************************/
/* */
/* Function name: getShares */
/* Description: read the shares from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses the file to get the number of shares owned
void getShares(ifstream& ifs, int shares[], int i) {
ifs >> shares[i]; // reads in the number of shares owned
}
/*********************************************************************/
/* */
/* Function name: outputResults */
/* Description: this will output the stock symbol, current price,
*/
/* bought price, and the number of shares owned */
/* Parameters: none */
/* Return value: s[i], c[i], b[i], and shares */
/* */
/*********************************************************************/
// this will output the possible buy stocks
void outputResults(string s[], float c[], float b[], int shares[], int& numberRead) {
cout << setw(10) << "Stock Symbol" << setw(15) << "Current Price" << setw(14) << "Bought Price" << setw(15) << "Shares Owned " << endl;
for (int i=0; i < numberRead; i++){
if (shares[i] < 100 && c[i] <= b[i]) //determines
whether or not stock is a "buy" stock
{ cout << setw(4) << s[i] << setw(15) <<
c[i] << setw(15) << b[i] << setw(12) <<
shares[i] << endl;
}
}
}
Header:
#ifndef STOCKS_H
#define STOCKS_H
using namespace std;
#include<string>
//Class definition
class stocks
{
public:
//constructor
stocks();
//declare functions
int setSharesOwned();
float setCurrentPrice();
float setPurchasePrice();
string setName();
void output(int, float, float, string);
private:
//declare variables
string stockSymbol;
int numSharesOwned;
float currentPrice, buyPrice;
};
#endif
#ifndef STOCKS_H
#define STOCKS_H
using namespace std;
#include <string>
//Class definition
class stocks {
public:
//constructor
stocks();
//declare functions
void setSharesOwned(int);
void setCurrentPrice(float);
void setPurchasePrice(float);
void setName(string);
void output();
private:
//declare variables
string stockSymbol;
int numSharesOwned;
float currentPrice, buyPrice;
};
#endif
#include "stocks.h"
#include <iostream>
#include <iomanip>
using namespace std;
stocks::stocks() {
stockSymbol = "";
currentPrice = 0;
buyPrice = 0;
numSharesOwned = 0;
}
void stocks::setCurrentPrice(float price) {
this->currentPrice = price;
}
void stocks::setName(string name) {
this->stockSymbol = name;
}
void stocks::setPurchasePrice(float price) {
this->buyPrice = price;
}
void stocks::setSharesOwned(int shares) {
this->numSharesOwned = shares;
}
void stocks::output() {
if (this->numSharesOwned < 100 && this->currentPrice <= this->buyPrice) { //determines whether or not stock is a "buy" stock
cout << setw(4) << this->stockSymbol << setw(15) << this->currentPrice << setw(15) << this->buyPrice << setw(12) << this->numSharesOwned << endl;
}
}
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <string>
#include <stdlib.h>
#include "stocks.h"
using namespace std;
// read the data file, store in arrays
int openDatafile(ifstream&, stocks[]); // opens the data file
void readData(ifstream&, stocks[], const int MAX, int&); // reads in the information from data file
void getSymbol(ifstream&, stocks[], int); // reads in the symbol
void getCurrent(ifstream&, stocks[], int); // reads in the current price of the stock
void getBought(ifstream&, stocks[], int); // reads in the bought price of the stock
void getShares(ifstream&, stocks[], int); // reads in the number of shares owned
void outputResults(stocks[], int&); // output the possible buy stocks for user
int main()
{
ifstream ifs;
const int MAX = 100; // 100 is max number of stocks that will be read in from file
stocks s[MAX]; // to hold stock objects
openDatafile(ifs, s);
int numberRead = 0;
readData(ifs, s, MAX, numberRead);
outputResults(s, numberRead);
system("pause");
return 0;
}
/*********************************************************************/
/* */
/* Function name: openDataFile */
/* Description: opens the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
//gets the user to type in the file name
int openDatafile(ifstream& ifs, stocks s[])
{
int i;
ifs.open("stocks.dat"); // opens data file
if (ifs.fail()) {
cout << "Error opening file: stocks.dat" << endl; // throws an error message if fails
exit(1);
}
}
/*********************************************************************/
/* */
/* Function name: readData */
/* Description: gets the name of the data file from user */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// reads in the data from the file
void readData(ifstream& ifs, stocks s[], const int MAX, int& i)
{
for (; i < MAX && !ifs.eof(); i++) { // creates the loop for going through file
getSymbol(ifs, s, i);
getCurrent(ifs, s, i);
getBought(ifs, s, i);
getShares(ifs, s, i);
}
}
/*********************************************************************/
/* */
/* Function name: getSymbol *
/* Description: read the symbol from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses data file to get symbol
void getSymbol(ifstream& ifs, stocks s[], int i)
{
// reads in the number of shares from the data file
string name;
ifs >> name;
s[i].setName(name);
}
/*********************************************************************/
/* */
/* Function name: getCurrent */
/* Description: read the current price from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses data file to get the current prices of the stock
void getCurrent(ifstream& ifs, stocks s[], int i)
{
float c;
ifs >> c; // reads in the current price of the stock
s[i].setCurrentPrice(c);
}
/*********************************************************************/
/* */
/* Function name: getBought */
/* Description: read the bought price from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses the file to get the bought prices of the stock
void getBought(ifstream& ifs, stocks s[], int i)
{
float b;
ifs >> b; // reads in the bought price of the stock
s[i].setPurchasePrice(b);
}
/*********************************************************************/
/* */
/* Function name: getShares */
/* Description: read the shares from the data file */
/* Parameters: none */
/* Return value: none */
/* */
/*********************************************************************/
// uses the file to get the number of shares owned
void getShares(ifstream& ifs, stocks s[], int i)
{
int shares;
ifs >> shares; // reads in the number of shares owned
s[i].setSharesOwned(shares);
}
/*********************************************************************/
/* */
/* Function name: outputResults */
/* Description: this will output the stock symbol, current price, */
/* bought price, and the number of shares owned */
/* Parameters: none */
/* Return value: s[i], c[i], b[i], and shares */
/* */
/*********************************************************************/
// this will output the possible buy stocks
void outputResults(stocks s[], int& numberRead)
{
cout << setw(10) << "Stock Symbol" << setw(15) << "Current Price" << setw(14) << "Bought Price" << setw(15) << "Shares Owned " << endl;
for (int i = 0; i < numberRead; i++) {
s[i].output();
}
}
A 45 50 10
B 25 30 25
C 60 55 20
D 60 90 36
E 45 55 104
The 4th deliverable is to create the program the makes the buy recommendation. It uses the...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...
I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...
Please help!! I am supposed to write a program in C++ about student & grades. Needs to have two functions that sorts students letter grade, and another one to sort Students name in your student’s record project. Remember, to add necessary parameters and declaration in main to call each function properly. Order of functions call are as follow Read Data Find Total Find average Find letter grade Call display function Call sort letter grade function Call display function Call sort...
//This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...
//This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...
I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...
I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words); int main() { // Declaring variables std::map<std::string,int> words; //defines an input stream for the data file ifstream dataIn; string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...
I wrote code in C++ that takes a text file containing information on different football players and their combine results, stores those players as a vector of objects of the class, and prints out those objects. Finally, I wrote a function that calculates the average weight of the players. MAIN.CPP: #include "Combine.h" #include using namespace std; // main is a global function // main is a global function int main() { // This is a line comment //cout << "Hello,...
Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...
Objectives: The main objective of this assignment is checking students’ ability to implement membership functions. After completing this assignment, students will be able to: implement member functions convert a member function into a standalone function convert a standalone function into a member function call member functions implement constructors use structs for function overloading Problem description: In this assignment, we will revisit Assignment #1. Mary has now created a small commercial library and has managed...