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

Q4 c++ Write a program that uses a structure for storing the name of a stock, it

ID: 3686651 • Letter: Q

Question

Q4

c++

Write a program that uses a structure for storing the name of a stock, its estimated earnings per share, and its estimated price-to-eanings ratio. Have the program prompt the user to enter these items for five different stocks, each time using the same structure to store the entered data. When the data has been entered for a particular stock, have the program compute and display the stock price anticipated on the basis of the entered earnings and price-per-share values. For example, if a user entered the data XYZ 1.56 12. the anticipated price for ashareofXYZ stock would be 1.56*12 = $18.72.

Explanation / Answer

#include<iostream>
#include<cstdlib>

using namespace std;

struct StockInfo{
  
   string name;
   double earning;
   double ratio;
};
int main(){
   StockInfo stocks[5]; // declaring structure of 5 cars
  
   for(int i=0; i<5; i++){
       cout<<"Enter name for stock "<<(i+1)<<": ";
       cin>>stocks[i].name;
       cout<<"Enter estimated price and price to earning ratio for "<<(i+1)<<" : ";
       cin>>stocks[i].earning>>stocks[i].ratio;
   }
  
  
   for(int i=0; i<5; i++){
       cout<<"Anticipated price for a share of "
           <<stocks[i].name<<" stock would be "<<stocks[i].earning<<"*"<<
           stocks[i].ratio<<" = "<<(stocks[i].earning*stocks[i].ratio)<<endl;
   }
   return 0;
}


/*

sample run:

Enter name for stock 1: pravesh
Enter estimated price and price to earning ratio for 1 : 12
1.2
Enter name for stock 2: qwwee
Enter estimated price and price to earning ratio for 2 : 32
2
Enter name for stock 3: ewdwq
Enter estimated price and price to earning ratio for 3 : 78
3
Enter name for stock 4: fwqf
Enter estimated price and price to earning ratio for 4 : 34
3
Enter name for stock 5: vefg
Enter estimated price and price to earning ratio for 5 : 56
6
Anticipated price for a share of pravesh stock would be 12*1.2 = 14.4
Anticipated price for a share of qwwee stock would be 32*2 = 64
Anticipated price for a share of ewdwq stock would be 78*3 = 234
Anticipated price for a share of fwqf stock would be 34*3 = 102
Anticipated price for a share of vefg stock would be 56*6 = 336


*/