473,466 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

need an outline of how to write a code for my program

25 New Member
hey guys,

i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this.
i have to write the following code. this will be the last time i ask for an entire code or u can give me the outine of what to do and i ll do it by myself.
the description is the following:


the program will read a text file that contains historical price of a stock. The program will allow users to query the stock price of a particular date and output its statistics (mean price, median price and standard deviation) for any
specified period. it is menu driven and works as follows.
$ StockAnalyser
Enter the stock file name: bhp.csv
Number of records: 762, from 26/08/2002 to 26/08/2005
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: g
Date (dd/mm/yyyy): 23/03/2003
Price is not available for the date: 23/03/2003
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: g
Date (dd/mm/yyyy): 27/03/2003
Stock Price for BHP on 27/03/2003 is $9.3600
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: s
Start date (dd/mm/yyyy): 01/01/2004
End date (dd/mm/yyyy): 10/01/2004
Statistics of stock BHP for the period of 01/01/2004 - 10/01/2004 is:
Mean price: $12.1417 Median Price: $12.1800 Std Deviation: 0.2705
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: s
Start date (dd/mm/yyyy): 15/01/2004
End date (dd/mm/yyyy): 15/01/2004
The period you specify must be more than one day
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: x
Wrong input!
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: q
Thank you for using StockAnalyser (version 1.0)!
$
Input File Format
The historical price for a particular stock can be exported from most Stock Brokers. The files are in text format. Usually, one file contains the price of a particular stock for a certain
period. For example, the file bhp.csv is the price of BHP stock for the period from 26 August 2002 to 26 August 2005, as partially shown
below.
BHP,"27 Aug 2002",9.53,9.56,9.45,9.45,8117955
BHP,"26 Aug 2002",9.45,9.48,9.4,9.48,6990617
BHP,"28 Aug 2002",9.54,9.55,9.4,9.44,12771227
BHP,"29 Aug 2002",9.31,9.31,9.21,9.27,11986227
BHP,"30 Aug 2002",9.21,9.23,9.11,9.11,19340245
BHP,"02 Sep 2002",9.15,9.23,9.05,9.23,8681758
BHP,"03 Sep 2002",9.14,9.25,9.14,9.24,7833427
BHP,"04 Sep 2002",9,9.01,8.88,8.9,18221850
........
........
BHP,"17 Aug 2005",20.6,20.84,20.53,20.55,17867065
BHP,"18 Aug 2005",20.3,20.4,20.13,20.28,18604022
BHP,"19 Aug 2005",20.27,20.75,20.27,20.68,16486925
BHP,"22 Aug 2005",20.86,21.25,20.82,21.22,18694638
BHP,"23 Aug 2005",21.43,21.47,20.98,21.07,20581539
BHP,"24 Aug 2005",20.95,21.11,20.56,20.56,23072751
BHP,"25 Aug 2005",20.05,20.23,19.9,19.9,40871120
BHP,"26 Aug 2005",20.29,20.6,20.21,20.6,37759955
Each line or record contains the information on the stock for a particular day. It consists of seven
fields separated by “,”
first field name of the stock
second field date (notice that the date string is double quoted)
third field opening price
forth field highest bid
fifth field lowest bid
sixth field close price
seventh field volume
“StockAnalyser” only cares about the close price!
Notice that the file usually doesn’t have any records for weekends and public holidays and you
should not assume the records are in the order of dates!
bhp.csv can be downloaded from WeebCT.
Read a stock data file
“StockAnalyser” extracts the first (stock name), second (date) and sixth field (close price) from
the input file, and places these fields in a proper data structure.
Assume that “StockAnalyer” only supports data files containing stock prices after 01 January
2000, and each file will not have records of more than five years.
Get a price for a particular day
After extracting information from a file, “StockAnalyser” is ready to output the price of any date.
When users select menu [g], “StockAnalyser” asks for a date in a format of dd/mm/yyyy (e.g.
03/12/2003) outputs the price of the specified date or reports “Price is not available” for the date
if the file does not have the record.
Find the price of a particular date is a problem of search. You MUST use binary search
algorithm for the sake of speed.
Calculate the statistics of the price for a specified period
Users can also select menu [s] to request “StockAnalyer” to calculate the statistics of the price for
a specified period. In this case, “StockAnalyer” asks users for a starting and ending dates of the
period in a format of dd/mm/yyyy, and calculates the following statistics
- mean (average) price of the stock during this period
- median price of the stock during this period
- standard deviation of the stock price during this period
In a case that the stock file does not contain a record for either the staring date or the ending date.
“StockAnalyser” will set the staring date as the earliest date that is later than the specified starting
date and has a record in the file. For ending date, “StockAnalyzer” will set the ending date as the
latest date that are earlier than the specified ending date and has a record in the file.
For example, if a file contains records for 02/09/2004 and 05/09/2004 and no records for
03/09/2004 and 04/09/2004. If users specify 03/09/2004 as the starting date, “StockAnalyser”
will set the starting date as 05/09/2004. If users specify 04/09/2004 as the ending date,
“StockAnalyser” will set 02/09/2004 as the ending date.
Hints:
1) To use a binary search algorithm to find the price of a particular date, you need to sort the
records against the date field(s). Since date has three fields: day, month and year, sorting
against the date (multiple fields) is not an easy task. You may consider converting the date
into an integer in such a way that each date has a unique corresponding integer value. This
value can be used as the key to sort all records.
2) Find the median price of a period, you may need fully or partially sort the records of this
period against the price.
3) You may find this information useful. In a leap year, the number of days in February is 29.
and the following code is to check whether a year is a leap year or not
_Bool isleapyear(int year)
{
return ((year%400==0) || (year%4==0 && year%100 !=0));
}
Sep 26 '06 #1
4 2729
georges the man
25 New Member
hey guys,

i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this.
can any one give me the outine of what to do and i ll do it by myself.
need the steps and i do the rest.
the description is the following:


the program will read a text file that contains historical price of a stock. The program will allow users to query the stock price of a particular date and output its statistics (mean price, median price and standard deviation) for any
specified period. it is menu driven and works as follows.
$ StockAnalyser
Enter the stock file name: bhp.csv
Number of records: 762, from 26/08/2002 to 26/08/2005
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: g
Date (dd/mm/yyyy): 23/03/2003
Price is not available for the date: 23/03/2003
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: g
Date (dd/mm/yyyy): 27/03/2003
Stock Price for BHP on 27/03/2003 is $9.3600
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: s
Start date (dd/mm/yyyy): 01/01/2004
End date (dd/mm/yyyy): 10/01/2004
Statistics of stock BHP for the period of 01/01/2004 - 10/01/2004 is:
Mean price: $12.1417 Median Price: $12.1800 Std Deviation: 0.2705
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: s
Start date (dd/mm/yyyy): 15/01/2004
End date (dd/mm/yyyy): 15/01/2004
The period you specify must be more than one day
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: x
Wrong input!
Welcome to use the StockAnalyser (version 1.0)
[g] Get the price of a specific date
[s] Get the statistics of a period
[q] Quit
Please select [g,s,q]: q
Thank you for using StockAnalyser (version 1.0)!
$
Input File Format
The historical price for a particular stock can be exported from most Stock Brokers. The files are in text format. Usually, one file contains the price of a particular stock for a certain
period. For example, the file bhp.csv is the price of BHP stock for the period from 26 August 2002 to 26 August 2005, as partially shown
below.
BHP,"27 Aug 2002",9.53,9.56,9.45,9.45,8117955
BHP,"26 Aug 2002",9.45,9.48,9.4,9.48,6990617
BHP,"28 Aug 2002",9.54,9.55,9.4,9.44,12771227
BHP,"29 Aug 2002",9.31,9.31,9.21,9.27,11986227
BHP,"30 Aug 2002",9.21,9.23,9.11,9.11,19340245
BHP,"02 Sep 2002",9.15,9.23,9.05,9.23,8681758
BHP,"03 Sep 2002",9.14,9.25,9.14,9.24,7833427
BHP,"04 Sep 2002",9,9.01,8.88,8.9,18221850
........
........
BHP,"17 Aug 2005",20.6,20.84,20.53,20.55,17867065
BHP,"18 Aug 2005",20.3,20.4,20.13,20.28,18604022
BHP,"19 Aug 2005",20.27,20.75,20.27,20.68,16486925
BHP,"22 Aug 2005",20.86,21.25,20.82,21.22,18694638
BHP,"23 Aug 2005",21.43,21.47,20.98,21.07,20581539
BHP,"24 Aug 2005",20.95,21.11,20.56,20.56,23072751
BHP,"25 Aug 2005",20.05,20.23,19.9,19.9,40871120
BHP,"26 Aug 2005",20.29,20.6,20.21,20.6,37759955
Each line or record contains the information on the stock for a particular day. It consists of seven
fields separated by “,”
first field name of the stock
second field date (notice that the date string is double quoted)
third field opening price
forth field highest bid
fifth field lowest bid
sixth field close price
seventh field volume
“StockAnalyser” only cares about the close price!
Notice that the file usually doesn’t have any records for weekends and public holidays and you
should not assume the records are in the order of dates!
bhp.csv can be downloaded from WeebCT.
Read a stock data file
“StockAnalyser” extracts the first (stock name), second (date) and sixth field (close price) from
the input file, and places these fields in a proper data structure.
Assume that “StockAnalyer” only supports data files containing stock prices after 01 January
2000, and each file will not have records of more than five years.
Get a price for a particular day
After extracting information from a file, “StockAnalyser” is ready to output the price of any date.
When users select menu [g], “StockAnalyser” asks for a date in a format of dd/mm/yyyy (e.g.
03/12/2003) outputs the price of the specified date or reports “Price is not available” for the date
if the file does not have the record.
Find the price of a particular date is a problem of search. You MUST use binary search
algorithm for the sake of speed.
Calculate the statistics of the price for a specified period
Users can also select menu [s] to request “StockAnalyer” to calculate the statistics of the price for
a specified period. In this case, “StockAnalyer” asks users for a starting and ending dates of the
period in a format of dd/mm/yyyy, and calculates the following statistics
- mean (average) price of the stock during this period
- median price of the stock during this period
- standard deviation of the stock price during this period
In a case that the stock file does not contain a record for either the staring date or the ending date.
“StockAnalyser” will set the staring date as the earliest date that is later than the specified starting
date and has a record in the file. For ending date, “StockAnalyzer” will set the ending date as the
latest date that are earlier than the specified ending date and has a record in the file.
For example, if a file contains records for 02/09/2004 and 05/09/2004 and no records for
03/09/2004 and 04/09/2004. If users specify 03/09/2004 as the starting date, “StockAnalyser”
will set the starting date as 05/09/2004. If users specify 04/09/2004 as the ending date,
“StockAnalyser” will set 02/09/2004 as the ending date.
Hints:
1) To use a binary search algorithm to find the price of a particular date, you need to sort the
records against the date field(s). Since date has three fields: day, month and year, sorting
against the date (multiple fields) is not an easy task. You may consider converting the date
into an integer in such a way that each date has a unique corresponding integer value. This
value can be used as the key to sort all records.
2) Find the median price of a period, you may need fully or partially sort the records of this
period against the price.
3) You may find this information useful. In a leap year, the number of days in February is 29.
and the following code is to check whether a year is a leap year or not
_Bool isleapyear(int year)
{
return ((year%400==0) || (year%4==0 && year%100 !=0));
}
Sep 26 '06 #2
Banfa
9,065 Recognized Expert Moderator Expert
this will be the last time i ask for an entire code or u can give me the outine of what to do and i ll do it by myself.
the description is the following
This is unlikely to happen, remember most of us here have plenty of other things to be doing other than righting your code or pseudo coding your program.

Try doing it yourself. You may be feeling over whelmed by the size of the task, this is not uncommon it happens to all of us. The thing to do is to pick a small piece of the task that you can solve and solve it. Then pick another small piece and solve it. Once you have done this a few times you will find that you have actually solved the entire task.

Most tasks are too big to be contemplated in 1 chunk.

As a pointer here are some small tasks that you could start by solving.

1. Create the user interface, menu outputs and user inputs without putting any program logic behind them yet.

2. Decide how you will store the data read from the file. What structures will you need, how will the memory for these structures be allocated, how will these structures be accessed.

3. Related to 2, write the code to open and read the file parsing the data. Prove it by writing it all out to a new file that you can compare to the original.
Sep 27 '06 #3
Banfa
9,065 Recognized Expert Moderator Expert
Also please stop double posting
Sep 27 '06 #4
georges the man
25 New Member
sorry for the double posting. but i am so frustrated trying to do write this program. i actualy did some of the code.
my code is the following:


#include <stdio.h>
#include <stdlib.h>

#define max_r 762
#define max_c 7

typedef enum
{jan=1,feb=2,mar=3,apr=4,may=5,jun=6,jul=7,aug=8,s ep=9,oct=10,nov=11,dec=12}month;

typedef struct {
int date;
int month;
int year;
}DATE;

typedef struct {
char stockName[20];
DATE date;
int closePrice;
}BHP;

char filename[15];

FILE * pFile;

/*functions prototypes*/
unsigned char OpenFile();
void clearStdin(void);
char menu();

int main()
{

long lSize;
char * buffer;
unsigned char quit=0; /*used to terminate the program = exit*/
char menuoption; /* identifies the menu used*/
unsigned char FileOpened=0; /* used to open the file intended to read*/
int day, year;
char month[4];
int i,j;
char read;

pFile = fopen("bhp.csv","r");
if(pFile == NULL)
{
printf("Error opening the file!!!\n\n");
return 0;
}

/*obtain file size.*/
fseek (pFile,0, SEEK_END);
lSize = ftell (pFile);
rewind (pFile);

/* allocate memory to contain the whole file.*/
buffer = (char*) malloc (lSize);
if (buffer == NULL)
{
printf("not enough memory!!!");
return 0;
}
/**********/

/* copy the file into the buffer.*/
for(i=0;i<max_r;++i)*/ /*specify what to read*/
/*for(j=0;j<1;++j)
{
fgets(buffer,max_r, pFile); */ /*read from the file bhp.csv*/
/*}*/


/*** the whole file is loaded in the buffer. ***/

/*opening the file and the operations*/
while(quit==0) /* check that the entered option is valid*/
{
if(FileOpened==0)
FileOpened=OpenFile();
else{
menuoption=menu(); /* display menu an get the option entered */

if(menuoption=='g'){
for(i=0;i<max_r;++i)
fgets(buffer,4,pFile);
puts(buffer);
printf("the buffer is %s", read); /*g option is selected*/
printf("\nDate (dd/mm/yyyy):");
}
else if(menuoption=='s'){ /*s option is selected*/
printf("User pressed s\n");
}
else if (menuoption=='q'){ /*q option is selcted*/
printf("\n\n\nThank you for using StockAnalyser verion (1.0)\n\n");

quit=1;
}
else{
printf("Wrong Input\n");
}
}

}

/* termiate*/

fclose (pFile);
free(buffer);

return 0;
}
unsigned char OpenFile()
{


printf("$ StockAnalyser\n");
printf("Enter the stock file name:");
scanf("%s", filename);
printf("Filename to open: %s\n\n", &filename);
pFile = fopen(filename,"r"); /* open the file to read*/

if (pFile == NULL) /*checks if the program is open correctly*/
{
printf("Error opening file %s\n\n", &filename);
return 0;
}
printf("\n\n");
printf("Number of records: 762 from 26/08/2002 to 26/08/2005\n\n");
printf("Welcome to use StockAnalyser (version 1.0)\n\n\n");
return 1;

return 0;
}

void clearStdin(void) /* remove wrong characters from stdin */
{
scanf("%*[^\n]"); /* skip to the end-of-line */
scanf("%*1[\n]"); /* skip one new-line */
return;
}

char menu()
{
char option;

clearStdin();
printf("[g] Get the price of a specific date\n");
printf("[s] Get the statistics of a period\n");
printf("[q] Quit\n");
printf(" please select [g, s or q]:");

scanf("%c", &option);

return option;
}

the problem is that i cant get anywhere from here.
i want to read and save the file into a 3D array so after that i can easily get the column and rows that i want. i choosed a 3D array so i can have one dimension for column other for row and the third for the lenght of the stream.
but this is my major problem. i know the logic but i cant write the code.
after i can save the data into the array i ll have then to sort the data. then i can use it.
so if u plz can give me some help doing this.
thanks
Sep 27 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Agent Mulder | last post by:
When C++ gives the programmer explicit control over the expansion of code, it needs a new specifier. If 'outline' as a specifier is too much out-of-line, one might consider unline as the...
4
by: Doors of Perception | last post by:
As you probably know, when you click on a link in MSIE and go to a page, then when you click the "back" button, you see a dotted box outlining the link on which I just clicked. As far as I'm...
20
by: Chris Bradbury | last post by:
Hi, I'm posting in this forum for the first time so if I break any conventions or protocols I'm sorry. I've attached this style: *:focus { outline: none } to a page but it doesn't remove...
4
by: Mark Jerde | last post by:
Sorry about the cross post. I'm not finding anything in google or google groups. I have a client who likes Visio-style drawings, similar to hierarchical org charts. But we're early in the...
5
by: Felix Collins | last post by:
Hi All, does anyone know any cleaver tricks to sort a list of outline numbers. An outline number is a number of the form... 1.2.3 they should be sorted in the following way... 1 1.1 1.2
1
by: John Doe | last post by:
I collapse an outline block, then copy it, then paste it. In my experience, the outline block always expands after the paste. Is their a way to modify the editor's behavior so that an outline block...
0
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
2
by: Joel Byrd | last post by:
I want to get a red outline around different divs on a page when I hover the mouse over them, and then have the red outline disappear on mouse out (basically to indicate that various elements on...
0
by: 1001 Webs | last post by:
As I read at: http://webpages.charter.net/edreamleo/front.html Leo is... * A general data management environment. Leo shows user-created relationships among any kind of data: computer...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.