473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

urgent

The purpose:
• Sorting and Searching
• Numerical Analysis


Design Specification
You are to write a program called “StockAnalyser”. Your 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. Your program must be 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. For this
assignment, you are given files that are exported from Commonwealth Security (CommSec). The
files are in text format. Usually, one file contains the price of a particular stock for a certain
period. For example, the sample file (bhp.csv) made available to you on WebCT contains 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));
}

the code i managed to write till now is:
#include <stdio.h>

char filename[15];
char StockName[20];

FILE* infile;




struct{
char StockName;
int date;
float ClosePrice;
}BHP;

char menu();
unsigned char OpenFile(void);

int main()
{
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,month,year;




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'){ /*g option is selected*/
printf("\nDate (dd/mm/yyyy):");
scanf("%d/%d/%d",&day,&month,&year);
if((day > 30) && (month == 2) ){
printf("Wrong date!!\n");
printf("february can't have more than 29 days!!!!\n\n");
}
else
printf("\n\nthe date choosed is %d/%d/%d\n\n", day,month,year);
}
else if(menuoption=='s'){ /*s option is selected*/
printf("User pressed s\n");
}
else if (menuoption=='q'){ /*q option is selcted*/
quit=1;
}
else{
printf("Wrong Input\n");
}
}

}
printf("\n\n\nThank you for using StockAnalyser verion (1.0)\n\n");









return 0;
}


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

if (infile == NULL) /*checks if the program is open correctly*/
{
printf("Error opening file %s\n\n", &filename);
return 0;
}
return 1;

}

char menu()
{
char option;

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");
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]:");
option = getch();
return option;
}

cant get the rest to work
Sep 18 '06 #1
0 2650

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

Similar topics

3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn"...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.