Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<iostream.h> #include<fstream.h> struct data { char name[30]; float curr

ID: 3535585 • Letter: #

Question

#include<iostream.h>

#include<fstream.h>

struct data

{

char name[30];

float current,last;

};

void main()

{

fstream file;

file.open("stocksprices.txt");

struct a[30],b;

for (int i=0;file!=eof;i++)

{

b=file.read((*ch)&b,sizeof(b));

a[i]=b;

}

int ch=1;

while(ch!=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>>ch;

switch(ch)

{

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.current;

}

}

break;

case 2:

for(j=0;j<=i;j++)

{

if(a[j]==b.name)

{

a=a[j].last-a[j].current;

cout<<"difference is "<<a;

}

}

break;

case 3:

for(j=0;j<=i;j++)

{

if(a[i].name==b.name)

{

a=[a[j].current-a[j-1].last;

cout<<"increase in price is "<<a;

}

}

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].price;

}

}

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 a=0;

for(j=0;j<=i;j++)

{

if(a[j].current>a[j].last)

{

tot=tot+(a[j].current-a[j].last);

a++;

}

}

tot=tot/a;

cout<<"average of increase in price is "<<tot;

break;

default:

cout<<"enter correct option";

break;

}

}

}

Explanation / Answer

program run correctly plz rate me 5...and provide me poiunts 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;

}

}

}