The compiler is taking my code here - // stocks.cpp : Defines the entry point for the console application.
-
//
-
-
//#include "stdafx.h"
-
-
#include <iostream>
-
#include <fstream>
-
#include <string>
-
-
using namespace std;
-
-
struct stock {
-
char company[256];
-
char symbol[4];
-
double price;
-
double change;
-
double old_price;
-
};
-
-
// global data that is accessible by all of the functions
-
const int fixed_array_size = 50;
-
stock stocks[fixed_array_size];
-
int amount_actually_read;
-
-
// functions
-
stock read_stock(ifstream &);
-
-
void print_all();
-
void print_by_groups();
-
void print_sorted_by_col();
-
void print_one(stock);
-
-
int compare_by_price(const void *, const void *);
-
int compare_by_symbol(const void *, const void *);
-
-
int main()
-
{
-
-
-
ifstream data_file= ifstream("c:\\data.txt");
-
int i=0;
-
-
while (i<fixed_array_size) {
-
-
if (data_file.eof()) break;
-
stocks[i] = read_stock(data_file);
-
i++;
-
-
}
-
-
amount_actually_read = i - 1;
-
-
-
-
-
-
print_all();
-
-
cout << endl << "----------------------------------------------------------------------------" <<endl;
-
-
qsort(stocks,amount_actually_read, sizeof(stock), compare_by_price);
-
-
print_by_groups();
-
-
-
cout << endl << "----------------------------------------------------------------------------" <<endl;
-
-
qsort(stocks,amount_actually_read, sizeof(stock), compare_by_symbol);
-
-
print_all();
-
-
cin >> *(new int);
-
return 0;
-
-
-
}
-
-
stock read_stock(ifstream &input_file) {
-
stock result;
-
-
input_file >> result.symbol;
-
input_file >> result.company;
-
input_file >> result.price;
-
input_file >> result.change;
-
//input_file >> endl;
-
-
result.old_price = result.price - result.change;
-
-
-
-
return result;
-
}
-
-
-
void print_one(stock a) {
-
-
cout.width(30);
-
cout << a.company;
-
-
cout.width(7);
-
cout << a.symbol;
-
-
cout.width(7);
-
cout << a.price;
-
-
cout.width(8);
-
cout << a.change;
-
-
cout.width(13);
-
cout << a.old_price << endl;
-
}
-
void print_all() {
-
-
cout.setf(ios::adjustfield, ios::right);
-
-
cout.width(30);
-
cout << "Company";
-
-
cout.width(7);
-
cout << "Symbol";
-
-
-
-
cout.width(7);
-
cout << "Price";
-
-
cout.width(8);
-
cout << "Change";
-
-
cout.width(13);
-
cout << "Old Price" << endl << endl << flush;
-
-
for (int i = 0; i < amount_actually_read; i++) {
-
-
print_one(stocks[i]);
-
}
-
}
-
-
void print_by_groups() {
-
-
double l = 0.00;
-
double r = 0.00;
-
char group_label = 'a';
-
int i =0,j,k=0;
-
-
double delimeters[] = {25.0, 50.0, 100.0,1000.0};
-
-
do {
-
-
l = r;
-
r = delimeters[k];
-
-
if (l!=0 & r!=1000)
-
cout << "Stocks in range [" << l <<"," << r <<"]"<<endl;
-
else if (l==0)
-
cout << "Stocks with price under " << r << endl;
-
else if (r==1000)
-
cout << "Stockt with price above " << l << endl;
-
-
-
-
while (stocks[i].price > l && stocks[i].price <= r && i<amount_actually_read) {
-
-
print_one(stocks[i]);
-
i++;
-
-
}
-
-
cout << endl;
-
-
-
-
k++;
-
} while(l!=1000 && i != amount_actually_read);
-
-
-
}
-
-
int compare_by_price(const void* _a, const void* _b) {
-
const stock *a = (const stock *) _a;
-
const stock *b = (const stock *) _b;
-
if (a->price < b->price) return -1;
-
else if (a->price == b->price) return 0;
-
else return 1;
-
}
-
-
int compare_by_symbol(const void* _a, const void* _b) {
-
const stock *a = (const stock *) _a;
-
const stock *b = (const stock *) _b;
-
if (string(a->symbol) < string(b->symbol)) return -1;
-
else if (string(a->symbol) == string(b->symbol)) return 0;
-
else return 1;
-
}
-
and doing this to it, marking it up like my professor would, what is GOING ON??? - * function are allowed. If there are multiple callbacks, they are
-
* invoked in the order they were registered.
-
*/
-
void
-
register_callback(event_callback __fn, int __index);
-
-
protected:
-
//@{
-
/**
-
* @if maint
-
* ios_base data members (doc me)
-
* @endif
-
*/
-
streamsize _M_precision;
-
streamsize _M_width;
-
fmtflags _M_flags;
-
iostate _M_exception;
-
iostate _M_streambuf_state;
-
//@}
-
-
// 27.4.2.6 Members for callbacks
-
// 27.4.2.6 ios_base callbacks
-
struct _Callback_list
-
{
-
// Data Members
-
_Callback_list* _M_next;
-
ios_base::event_callback _M_fn;
-
int _M_index;
-
_Atomic_word _M_refcount; // 0 means one reference.
-
-
_Callback_list(ios_base::event_callback __fn, int __index,
-
_Callback_list* __cb)
-
: _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
-
-
void
-
_M_add_reference() { __gnu_cxx::__atomic_add(&_M_refcount, 1); }
-
-
// 0 => OK to delete.
-
int
-
_M_remove_reference()
-
{ return __gnu_cxx::__exchange_and_add(&_M_refcount, -1); }
-
};
-
-
_Callback_list* _M_callbacks;
-
i think that's enough of an example as it is nearing a thousand lines of feedback for me to digest. what the???????? Anyone-
2 2872 JosAH 11,448
Recognized Expert MVP
The compiler is taking my code here
<snip>
and doing this to it, marking it up like my professor would, what is GOING ON???
<snip>
i think that's enough of an example as it is nearing a thousand lines of feedback for me to digest. what the???????? Anyone-
Which flags did you pass to your compiler? The output looks like you just
preprocessed your sources using the -E or -P flag.
kind regards,
Jos
If I did it was inadvertant, at least I know Dev didn't develop some more problems on me-I'm not fond of using VS as my only choice.
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: William Buch |
last post by:
I have a strange problem. The code isn't written by me, but uses the
qsort function in stdlib. ALWAYS, the fourth time through, the memory
location of variable list (i.e. mem location = 41813698) becomes 11,
then the program crashes. It is obviously qsort that may me
overwritten the used memory location. The weird thing is that it is...
|
by: Steve |
last post by:
can someone tell me how qsort function in <stdlib.h> is used
(qsort(..........))?
the function has a buffer, two void * parameters and the a pointer to a
compare function. Thanks.
|
by: buda |
last post by:
I had some spare time and decided to try to implement the standard library
qsort. This is a pretty simpleminded attempt, but it seems to be working. I
have to point out that efficiency is not at all an issue for me, and this is
purely a toy, so to speak. I'm quite aware that this is not the quickest way
to implement the quicksort algorithm,...
|
by: John Smith |
last post by:
I'm trying to figure out qsort(). I haven't seen any practical examples,
only synopsis. In the code below, the array is not sorted. Can someone
give me some help?
#include <stdio.h>
#include <stdlib.h>
int compare(const void* a, const void* b);
int main(void)
{
|
by: t_pantel |
last post by:
I 've got the following structure:
typedef struct GROUPED
{
short val ;
short code;
short group;
short forecast_cd;
short double_ind;
short min;
| |
by: yatindran |
last post by:
hai
this is my 2d array.
int a = {
{5,2,20,1,30,10},
{23,15,7,9,11,3},
{40,50,34,24,14,4},
{9,10,11,12,13,14},
{31,4,18,8,27,17},
{44,32,13,19,41,19},
{1,2,3,4,5,6},
|
by: PCHOME |
last post by:
Hi!
I have questions about qsort( ). Is anyone be willing to help?
I use the following struct:
struct Struct_A{
double value;
...
} *AA, **pAA;
|
by: bsder |
last post by:
Hi,
Can anyone please tell me how to calculate the size of the following
4-dimensional array, and now to use qsort for sorting on this array?
double sp = { 4.0, 5.0, 6.0 };
double spa = {
{ 4.0, 2.0 },
{ 5.0, 8.0 },
{ 6.0, 6.0 },
|
by: gauss010 |
last post by:
Suppose I have an object A of type char. Each A is a buffer
containing a string, and I want to sort the M strings of A using the
strcmp function. The description of the qsort function says that I
must pass a pointer to the first object of the array to be sorted.
This leads me to write the following:
char A;
int cmp(const void *a, const...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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. ...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |