No Loops, or if statements, or arrays allowed for this program. You will receive a zero if your program contains any loop, if statement, or array. You need a program to maintain information about your stocks. Assume that you have the following stocks:
Stock Name Number of Shares Buying Price Current Price Yearly Fees
Per Share Per Share
IBM 155 $15.33 $13.33 $5.00
ORACLE 375 $11.77 $12.25 $3.50
SUN MICRO 350 $27.55 $35.75 $12.25
LINKSYS 85 $25.35 $23.34 $6.00
CISCO 50 $45.36 $50.86 $1.50
You must use the data from this table for you Program Set 2 submission.
Write a C program that will perform the following tasks:
Task 1: Allow the user to enter in the data for each stock. Stock name, Number of shares, Buy Price, Current Price and Yearly fees.(The user will not enter the

Respuesta :

Answer:

Here is the C program:

#include <stdio.h> //to use input output functions

int main(){ //start of main function

    char *stock_name=NULL; //to store stock name (this is used instead of using char type array)

    int shares; //to store number of shares

    float buy_price; //to store the buy price

    float cur_price; //to store the current price

    float fees; //to store the fees

    double initial_cost; //to store the computed initial cost

    double current_cost; //to store the value of computed current cost

    double profit; //to store the calculated value of profit

printf("enter stock name ");  //prompts to enter stock name

scanf("%m[^\n]",&stock_name); //reads the input stock name

printf("enter number of shares "); //prompts to enter number of shares

scanf("%d", &shares); //reads the input number of shares

printf("enter the buy price, current price and fees "); //prompts to enter buy price, current price and fees values from user

scanf("%f %f %f", &buy_price, &cur_price, &fees); //reads the values of buy price, current price and fees from user

    initial_cost = shares * buy_price; //computes initial cost

    current_cost = shares *cur_price; //computes current cost

    profit = current_cost - initial_cost - fees; //computes profit for each stock

printf("The stock name is: %s\t\n",stock_name); //displays the stock name

printf("The number of shares: \t%d\t\t\n",shares); //displays the number of shares

printf("The buy price is:\t$\t %0.2f\t\n",buy_price); //displays the buy price

printf("The current price is:\t$\t %0.2f\n",cur_price); //displays the current price

printf("The fees are:\t\t$\t %0.2f\n",fees); //displays the fees

printf("The initial cost is:\t$\t %0.2f\n",initial_cost); //displays the computed initial cost

printf("The current cost is:\t$\t %0.2f\n",current_cost); //displays the computed current cost

printf("The profit is:\t\t$\t %0.2f\n",profit);//displays the computed profit for each stock

return 0;  }

       

Explanation:

Lets say the user input IBM, 150, 11.33 13.33 and 5.00 as stock name, number of shares, buy price, current price and fees values.

So,

stock_name = "IBM"

shares = 150

buy_price = 11.33

cur_price = 13.33

fees = 5.00

Now initial cost is computed as:

  initial_cost = shares * buy_price;

This becomes:

  initial_cost = 150* 11.33

  initial_cost = 1699.5

Next current cost is computed as:

    current_cost = shares *cur_price;

This becomes:

    current_cost = 150*13.33

    current_cost = 1999.5

Next the profit is computed as:

    profit = current_cost - initial_cost - fees;

This becomes:

    profit = 1999.5 - 1699.5 - 5.00

     profit =     295

These values are displayed on the output screen up to 2 decimal places. So the output of the entire program is:

The stock name is: IBM                                                                                                                        The number of shares:   150                                                                                                                   The buy price is:         $        11.33                                                                                                        The current price is:   $        13.33                                                                                                        The fees are:               $        5.00                                                                                                         The initial cost is:        $        1699.50                                                                                                      The current cost is:     $        1999.50                                                                                                      The profit is:                 $        295.00

The screenshot of the output is attached.

Ver imagen mahamnasir
RELAXING NOICE
Relax

Otras preguntas

s.)
Task 2: Calculate the Initial Cost, Current Cost, and Profit for each stock. The formulas to use are: Initial Cost

Respuesta :

Answer:

Here is the C program:

#include <stdio.h> //to use input output functions

int main(){ //start of main function

    char *stock_name=NULL; //to store stock name (this is used instead of using char type array)

    int shares; //to store number of shares

    float buy_price; //to store the buy price

    float cur_price; //to store the current price

    float fees; //to store the fees

    double initial_cost; //to store the computed initial cost

    double current_cost; //to store the value of computed current cost

    double profit; //to store the calculated value of profit

printf("enter stock name ");  //prompts to enter stock name

scanf("%m[^\n]",&stock_name); //reads the input stock name

printf("enter number of shares "); //prompts to enter number of shares

scanf("%d", &shares); //reads the input number of shares

printf("enter the buy price, current price and fees "); //prompts to enter buy price, current price and fees values from user

scanf("%f %f %f", &buy_price, &cur_price, &fees); //reads the values of buy price, current price and fees from user

    initial_cost = shares * buy_price; //computes initial cost

    current_cost = shares *cur_price; //computes current cost

    profit = current_cost - initial_cost - fees; //computes profit for each stock

printf("The stock name is: %s\t\n",stock_name); //displays the stock name

printf("The number of shares: \t%d\t\t\n",shares); //displays the number of shares

printf("The buy price is:\t$\t %0.2f\t\n",buy_price); //displays the buy price

printf("The current price is:\t$\t %0.2f\n",cur_price); //displays the current price

printf("The fees are:\t\t$\t %0.2f\n",fees); //displays the fees

printf("The initial cost is:\t$\t %0.2f\n",initial_cost); //displays the computed initial cost

printf("The current cost is:\t$\t %0.2f\n",current_cost); //displays the computed current cost

printf("The profit is:\t\t$\t %0.2f\n",profit);//displays the computed profit for each stock

return 0;  }

       

Explanation:

Lets say the user input IBM, 150, 11.33 13.33 and 5.00 as stock name, number of shares, buy price, current price and fees values.

So,

stock_name = "IBM"

shares = 150

buy_price = 11.33

cur_price = 13.33

fees = 5.00

Now initial cost is computed as:

  initial_cost = shares * buy_price;

This becomes:

  initial_cost = 150* 11.33

  initial_cost = 1699.5

Next current cost is computed as:

    current_cost = shares *cur_price;

This becomes:

    current_cost = 150*13.33

    current_cost = 1999.5

Next the profit is computed as:

    profit = current_cost - initial_cost - fees;

This becomes:

    profit = 1999.5 - 1699.5 - 5.00

     profit =     295

These values are displayed on the output screen up to 2 decimal places. So the output of the entire program is:

The stock name is: IBM                                                                                                                        The number of shares:   150                                                                                                                   The buy price is:         $        11.33                                                                                                        The current price is:   $        13.33                                                                                                        The fees are:               $        5.00                                                                                                         The initial cost is:        $        1699.50                                                                                                      The current cost is:     $        1999.50                                                                                                      The profit is:                 $        295.00

The screenshot of the output is attached.

Ver imagen mahamnasir
RELAXING NOICE
Relax

Otras preguntas