Google Answers Logo
View Question
 
Q: basic C++ code ( No Answer,   1 Comment )
Question  
Subject: basic C++ code
Category: Computers > Programming
Asked by: jm43-ga
List Price: $5.00
Posted: 21 Mar 2006 06:39 PST
Expires: 20 Apr 2006 07:39 PDT
Question ID: 710017
code a c++ program that inputs a series of 24 hourly temperatures from
a file and outputs a bar chart (using stars) of the temeratures for
the day.thetemperature should be printed to the left of the
corisponding bar and there should be a heading that gives the scale of
the chart. the range of the tempertures should be from -30 to 120.
Because it is hard to display 150 characters on the screen you should
have each star represent a range of three degrees.
Answer  
There is no answer at this time.

Comments  
Subject: Re: basic C++ code
From: rodneywa-ga on 21 Mar 2006 15:10 PST
 
/*
--- Sample Input from myfile.txt ---
120
84
77
75
31
111
-10
-8
78
1
55
60
60
31
32
23
33
44
68
108
71
26
107

--- Sample Output ---

             -30**************************************************120
120.000000:     **************************************************
84.000000:      **************************************
77.000000:      ************************************
75.000000:      ***********************************
31.000000:      *********************
111.000000:     ***********************************************
-10.000000:     *******
-8.000000:      ********
78.000000:      ************************************
1.000000:       ***********
55.000000:      *****************************
60.000000:      ******************************
60.000000:      ******************************
31.000000:      *********************
32.000000:      *********************
23.000000:      ******************
33.000000:      *********************
44.000000:      *************************
68.000000:      *********************************
108.000000:     **********************************************
71.000000:      **********************************
26.000000:      *******************
107.000000:     **********************************************

--- c++ code ---

#include <stdio.h>

int main ()
{
        char str [150];
        float f,v;
        FILE * pFile;
        int i;
        pFile = fopen ("myfile.txt","r");
        printf("\t    
-30**************************************************120\n");
        while((fscanf(pFile, "%f", &f))!=EOF)
        {
                printf ("%f: \t",f);
                v=(f+30)/3;
                for(i=0;i<v;i++)
                        printf("*");
                printf("\n");
        }
        fclose (pFile);
        return 0;
}

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy