see picture I have a file titled \"stockPrices.txt\" that contains the following
ID: 3535093 • Letter: S
Question
see picture
I have a file titled "stockPrices.txt" that contains the following Information on 10 stocks: Stock Name Current Price Last Weeks Price Your program should open this file and input all information into an array of a custom you have built to handle the information. From this point forward, all output can go to the screen, You should display a menu to the user similar to the following: What would you like to do with your stock information? Display stocks with a current value over $20 Display stocks that have decreased in value since last Display stocks that have increased by over 20% since last week Display all stocks with both prices Display the average of all current stock prices Display the average increase of stock prices Exit Please make a selection: You should add the functionality to perform every item within the list. When it performs the selected feature, it should return to the menu and allow the user to continue working with the selected stockExplanation / Answer
program run correctly plz rate me 5....thnx... :)
#include<iostream.h>
#include<fstream.h>
#include<string.h>
struct data
{
char name[30];
float current,last;
};
void main()
{
fstream file;
file.open("stocksprices.txt",ios::in,ios::out);
data a[30],b;
char *ch;
for (int i=0;file!="EOF";i++)
{
file.read((char *)&b,sizeof(b));
a[i]=b;
}
int c=1,j;
while(c!=7)
{
cout<<"what you want to know from stock market 1.current value 2.decrease value from last week 3.increase from last week 4.display all stocks 5.avg of all current price 6.average in increadeof stock price 7.exit";
cin>>c;
switch(c)
{
cout<<"enter the name of stock you want information";
cin>>b.name;
case 1:
for(j=0;j<=i;j++)
{
if(a[j].name==b.name)
{
cout<<"current price is "<<a[j].current;
}
}
break;
case 2:
for(j=0;j<=i;j++)
{
if(a[j].name==b.name)
{
float x;
x=a[j].last-a[j].current;
cout<<"difference is "<<x;
}
}
break;
case 3:
for(j=0;j<=i;j++)
{
if(a[i].name==b.name)
{
float x;
x=a[j].current-a[j-1].last;
cout<<"increase in price is "<<x;
}
}
break;
case 4:
for(j=0;j<=i;j++)
{
if(a[j].name==b.name)
{
cout<<"curent price is "<<a[j].current<<" last week price is "<<a[j].last;
}
}
break;
case 5:
float tot=0;
for(j=0;j<=i;j++)
{
tot=a[j].current;
}
tot=tot/(i);
cout<<"average is "<<tot;
break;
case 6:
tot=0;
int x=0;
for(j=0;j<=i;j++)
{
if(a[j].current>a[j].last)
{
tot=tot+(a[j].current-a[j].last);
x++;
}
}
tot=tot/x;
cout<<"average of increase in price is "<<tot;
break;
default:
cout<<"enter correct option";
break;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.