473,748 Members | 10,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can i get any help writing this program?

25 New Member
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,8117 955
BHP,"26 Aug 2002",9.45,9.48 ,9.4,9.48,69906 17
BHP,"28 Aug 2002",9.54,9.55 ,9.4,9.44,12771 227
BHP,"29 Aug 2002",9.31,9.31 ,9.21,9.27,1198 6227
BHP,"30 Aug 2002",9.21,9.23 ,9.11,9.11,1934 0245
BHP,"02 Sep 2002",9.15,9.23 ,9.05,9.23,8681 758
BHP,"03 Sep 2002",9.14,9.25 ,9.14,9.24,7833 427
BHP,"04 Sep 2002",9,9.01,8. 88,8.9,18221850
........
........
BHP,"17 Aug 2005",20.6,20.8 4,20.53,20.55,1 7867065
BHP,"18 Aug 2005",20.3,20.4 ,20.13,20.28,18 604022
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,40 871120
BHP,"26 Aug 2005",20.29,20. 6,20.21,20.6,37 759955
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
“StockAnal yser” 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
“StockAnal yser” 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 “StockAnal yer” 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, “StockAnal yser” is ready to output the price of any date.
When users select menu [g], “StockAnal yser” 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 “StockAnal yer” to calculate the statistics of the price for
a specified period. In this case, “StockAnal yer” 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.
“StockAnal yser” 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, “StockAnal yzer” 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, “StockAnal yser”
will set the starting date as 05/09/2004. If users specify 04/09/2004 as the ending date,
“StockAnal yser” 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=Open File();
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("februar y 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\nT hank 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("Filenam e 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 19 '06 #1
0 2423

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

Similar topics

4
2757
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like storing products in
10
2114
by: atlanta | last post by:
this is a simple C++ program to write. "Write a complete and functioning structured program that successfully compiles on Visual C++ 6, that uses two-dimensional array (5x5) that stores numbers. Read in the numbers, print them forward and backward." i dont know How to write C++.
27
2109
by: SK | last post by:
Hi I am trying to teach myself how to program in C. I am a physician hoping to be able to help restructure my office. Anyhow, I amhoping that the porblem I am having is simple to those much more experienced in programming. I am trying to use the concept of arrays to calculate the hours of my backoffice staff, however I am getting a ridiculous amount of error lines. If any one has time to help me that would be great. I am using the...
1
3717
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
12
2815
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if we enter 4, the size of four triangles are 4 rows. In addition, I am also writing a program which i started and failed in giving the right size of traingles. I will appreciate if somebody can help.
15
2579
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
12
3014
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed the instructions and couldnt get the correct results. heres the code stuff... temperature=input("what is the temperature of the spam?") if temperature>50: print "the salad is properly cooked." else:
1
1503
by: siva041986 | last post by:
Hi there, This is Siva. I need some help in writing a program for Unix. I need to write a program using Semaphores and avoid deadlocks and starvation. If you think you can help me please let me know. I really need your help badly. I will send you complete details of the program if you are ready to help me. Please let me know if you know Unix and its programming. Looking forward for ur reply. Thanks and regards, Siva.
5
3306
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
9548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
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 we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.