Friday, August 23, 2013

Strongly-typed non-scoped enums in C++11?

Newsgroup: comp.lang.c++

Subject: Strongly-typed non-scoped enums in C++11?

From: Paavo Helde <myfirstname@...>

Date: Fri, 23 Aug 2013 02:28:33 -0500





In C++11, you can have 'enum class abc' which is strongly-typed and

scoped, and 'enum abc: type' which are not scoped, but also not

strongly-typed. However, I would like to have a non-scoped strongly-typed

enum, is this possible somehow?



Background: I would like to have strongly-typed enums in order to find

out and fix suspicious comparisons and conversions to integers. However,

only one of our build machines has a compiler version which supports C++

11 enums, a legacy enum is needed for other builds. For the diagnostics

point of view it is fine if it works only in one build, so I thought

doing something like:



#ifdef HAS_C11_STRONGLY_TYPED_ENUMS

enum class abc {

#else

enum abc {

#endif

val1,

val2,

....

};



Alas, now all the codebase must be changed to use the names abc::val1,

abc::val2 in the C11 branch, and must not use the prefix in the legacy

branch. This seems to kill the whole benefit of this approach. Any ideas?



TIA

Paavo







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?72045-Strongly-typed-non-scoped-enums-in-C-11&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

passing by reference

Newsgroup: comp.lang.c++

Subject: passing by reference

From: bob smith <bob@...>

Date: Thu, 22 Aug 2013 22:05:28 -0700 (PDT)



How does passing by reference work behind the scenes?



Does the compiler secretly pass in a pointer to the object?



Thanks.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?72005-passing-by-reference&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Thursday, August 22, 2013

A Better Container Choice?

Newsgroup: comp.lang.c++

Subject: A Better Container Choice?

From: mrc2323@...

Date: Thu, 22 Aug 2013 12:52:37 -0700



My current application has 2 large data sets that are combined into a

single data set that I must access by (part of) a string value.

Currently I have the structure declared as a map object, but after

populating the basic information I am adding information from another

database that's much larger - in a many-to-one situation.

Here's the fundamental information I use:

struct Res_Struct // Individual Event Finisher data

{

int resEvtNum; // link to Events table

int resYear; // Event Year

int resOAll; // OverAll Finish position

int resD_P; // Division Place

long resTime; // Finish Time

} resWork;

struct Hist_Fins // individual Finisher's results

{

int evtNum; // Result's Event # link

string PRF; // P/R indicator

Res_Struct histInfo; // Finisher's result(s) info

} histWork;

vector<Hist_Fins>::iterator hIter;

struct Fin_Struct // Individual Finisher data

{

long finLink; // unique Finisher (link)

char finGender; // gender

int finCount; // # Finishes by this participant

string finName; // Finisher Name (Last, First M.)

string finDoB; // (derived) DoB from event Age/Year

vector<Hist_Fins> histVect;

} finWork;

map<int, Fin_Struct> finMap;

map<int, Fin_Struct>::iterator fIter;



Yes, this seems a bit convoluted, but the application has been

growing in size and complexity, and I've not had time to redesign...

The important issue here is that I have ~160,000 records that

construct the basic information in the Fin_Struct. My other data (~

400,000 records) comprise the information that populates the "histVect"

object - 1-200 vector items in each map object. The input data files

are flat text data files (referencing some earlier posts about file I/o

efficiency).

Note that the map has an integer key value, and values range from 101

through ~160,000. I don't use the "name" as a key because I normally

scan the entire map object to look for objects that match some part of

the name value (e.g. I want to find all objects with names that start

with "WAL", etc.).

The use of an STL map doesn't seem best, because I don't use the map

in a traditional way, and the loading of the map takes a lot of time

<sigh>. Since the data objects are consecutive in an integer range, I

wonder if another container would be a better choice. I could use a

vector (and reserve a good amount of space "going in", rather than let

slow runtime grow occur), but I think I'd lose significant "load time"

by not referencing a map as I'd have to scan the vector 400,000 or more

times during the 2nd file population...

Both files contain the integer value that links them, as well as the

"name" string.

Any thoughts? TIA







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?71655-A-Better-Container-Choice&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Tuesday, August 20, 2013

Singleton class in C++

Newsgroup: comp.lang.c++

Subject: Singleton class in C++

From: bob smith <bob@...>

Date: Mon, 19 Aug 2013 17:54:40 -0700 (PDT)



If someone asks you to write a Singleton class in C++, can someone help me see what the answer would be?



In particular, I don't know if the getInstance() function ought to return Singleton* or Singleton&.



I'm also concerned about when and how the memory for this class will be deallocated.



Thanks.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?69346-Singleton-class-in-C&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Monday, August 19, 2013

When might it make sense to use inheritance when templates (compile-time polymorphism) is enough?

Newsgroup: comp.lang.c++

Subject: When might it make sense to use inheritance when templates (compile-time polymorphism) is enough?

From: "K. Frank" <kfrank29.c@...>

Date: Sat, 17 Aug 2013 14:37:17 -0700 (PDT)



Hello Group!



Prior to templates, if you wanted to reuse code across

different types, you would use inheritance / polymorphism

where your different types would derive from a common

base type that offered the capabilities needed by your

reusable code.



Now (with templates) if you know at compile time which

objects are of which concrete types you can use templates.

(If the concrete type of an object is only determined at

run time, you still need inheritance.)



This is kind of a soft question, but I'm wondering whether

there are situations where inheritance would still be

preferable, even when concrete types are known at compile

time, and a template solution could have been used.



Assume for this question that the code is special purpose,

so we're not trying to write some general, open-ended

library. That is, the code will be reused across a

smallish number of different types that are all being

designed together, and will not be extended to new types

in the future.



Also assume that efficiency isn't a concern, so that we

don't care about the cost of vtables or the cost (size)

of duplicated template code.



To illustrate my question, below is a simple, do-nothing

example that uses both inheritance and templates for

compile-time polymorphism. printPrintable is an

inheritance-based polymorphic function, while

printHasPrintMe is a generic template function.





Thanks for any thoughts and wisdom.





K. Frank





==========



#include <iostream>



class Printable {

public:

virtual void printMePoly() const = 0;

};



class A : public Printable {

public:

void printMePoly() const { std::cout << "aValue_ = " << aValue_ << std::endl; }

int aValue_ = 13;

};



class B {

public:

void printMeGen() const { std::cout << "bValue_ = " << bValue_ << std::endl; }

int bValue_ = 17;

};



void printPrintable (const Printable& p) {

p.printMePoly();

}



template<typename T> void printHasPrintMe (const T& p) {

p.printMeGen();

}



int main (int argc, char *argv[]) {

A a;

B b;

printPrintable (a);

printHasPrintMe (b);

}



==========







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?67951-When-might-it-make-sense-to-use-inheritance-when-templates-(compile-time-polymorphism)-is-enough&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, August 18, 2013

Initializing member references to dummy member variables

Newsgroup: comp.lang.c++

Subject: Initializing member references to dummy member variables

From: "K. Frank" <kfrank29.c@...>

Date: Sun, 11 Aug 2013 20:29:56 -0700 (PDT)



Hello Group!



Suppose I have a class that has a member reference

variable, and sometimes I want to initialize it,

and sometimes I don't. How much sense does it make

to initialize it to a dummy member variable (to shut

the compiler up)?



As a concrete example, let's say I have a class that

is constructed with a value of or reference to some kind

of handle, but the handle might be a number or it might

be a string:



struct Handle {

Handle (int iHandle) :

iHandle_(iHandle),

sHandle_(dummy),

useIHandle_(true)

{}

Handle (const std::string& sHandle) :

iHandle_(0),

sHandle_(sHandle),

useIHandle_(false)

{}

const int iHandle_;

const std::string& sHandle_;

bool useIHandle_;

std::string dummy_;

}



The point is that the member reference variable sHandle_

is supposed to be initialized (in the constructors'

initialization lists), whether or not it's actually

going to be used. The constructor that takes an int

argument doesn't have any std::strings floating

around with which to initialize sHandle_, hence the

introduction of the member variable dummy_.



Is this a reasonable approach? Is there an established

idiom for doing this kind of thing?





Thanks for any wisdom.





K. Frank







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?63071-Initializing-member-references-to-dummy-member-variables&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Saturday, August 17, 2013

Selecting Container for "Top 20" Application

Newsgroup: comp.lang.c++

Subject: Selecting Container for "Top 20" Application

From: mrc2323@...

Date: Sat, 17 Aug 2013 12:07:18 -0700



I am looking for an STL container that will efficiently handle a "Top

20" list. Specifically, I have >300,000 data records that I must scan

to find and store the highest 20 values.

None of the available STL containers seems well suited for this

application. For example:

- array, even though fixed in size, seems cumbersome to use: no delete

or erase function is available; insertion at some point is difficult;

etc. Replacement of the "end value" and sorting might work, but it's

tedious and slow...

- vector, while having insert & erase functions, incurs repeated size

expansion (expensive!) and truncation to maintain a fixed size.

Appending a new value if it's greater than the 20th element, followed by

sorting and truncation might be less work, but it might be very slow to

execute.

- queue/deque, set, and stack seem inappropriate for this application,

and the others (map, list, etc.) are completely unusable here.

Am I missing something? Is/are there reasonably efficient ways to

use array or vector that are appropriate? TIA







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?67887-Selecting-Container-for-Top-20-Application&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Will "using declaration" introduce a conflict issue if we have a local function with an identical signature?

Newsgroup: comp.lang.c++

Subject: Will "using declaration" introduce a conflict issue if we have a local function with an identical signature?

From: junyangzou <zoujyjs@...>

Date: Fri, 16 Aug 2013 21:02:45 -0700 (PDT)



Consider the following code( an excerpt from "Effective C++, 3rd" Item 33 ):



#include <iostream>

using namespace std;



class Base{

private:

int x;

public:

virtual void mf1() = 0;

virtual void mf1(int){

cout << "mf1(int) in base" << endl;

}



virtual void mf2(){

cout << "mf2 in base" << endl;

}



void mf3(){

cout << "mf3 in base" << endl;

}



void mf3(double){

cout << "mf3(double) in base" << endl;

}

};



class Derived: public Base {

public:

using Base::mf1; // make all things in Base named mf1 and mf3

using Base::mf3; // visible (and public) in Derived's scope



virtual void mf1(){

cout << "mf1 in derived" << endl;

}



void mf3()----------------------------------(?)

{

cout << "mf3 in derived" << endl;

}



void mf4(){

cout << "mf4 in derived" << endl;

}

};







int main(){

Derived d;

int x = 0;

d.mf1(); // still fine, still calls Derived::mf1

d.mf1(x); // now okay, calls Base::mf1

d.mf2(); // still fine, still calls Base::mf2

d.mf3(); // fine, calls Derived::mf3

d.mf3(x); // now okay, calls Base::mf3

cin.get();



return 0;

}



Notice that the local mf3() has an identical signature with the synonym mf3() introduced by using Base::mf3. But this code will not get any complainant with g++.



And here in http://msdn.microsoft.com/zh-cn/library/was37tzw(v=VS.71).aspx.



Quote:

If a set of local declarations and using-declarations for a single name are given in a declarative region, they must all refer to the same entity, or they must all refer to functions. For example:

// functions_in_namespaces1.cpp

// C2874 expected

namespace B

{

int i;

void f(int);

void f(double);

}



void g()

{

int i;

using B::i; // error: i declared twice

void f(char);

using B::f; // ok: each f is a function

}

In the example above, the using B::i statement causes a second int i to be declared in the g() function. The using B::f statement does not conflict with the f(char) function because the function names introduced by B::f have different parameter types.



So, back to the title, will using introduce a conflict?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?67695-Will-using-declaration-introduce-a-conflict-issue-if-we-have-a-local-function-with-an-identical-signature&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

File Read Performance Issue

Newsgroup: comp.lang.c++

Subject: File Read Performance Issue

From: mrc2323@...

Date: Fri, 16 Aug 2013 18:41:48 -0700



I am developing an application that reads and stores data from 2

large text files. One file (5750kb) has ~160,000 records and the other

(23,000kb) has ~330,000 records. The program reads both files and

converts/stores their data into vectors. Also, some indices to unique

records are developed (much like a telephone book), so that searches can

be efficiently done.

The reads at program start take a long time (~2 minutes), and

although I use buffers of 4096 size, I can't see other ways to improve

this aspect of the program's performance. The data this program uses

will continue to grow, so I am concerned about its viability. Any

thoughts? TIA







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?67653-File-Read-Performance-Issue&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Wednesday, August 14, 2013

OT: Is this Comeau's real site is is it a phishing scam?

Newsgroup: comp.lang.c++

Subject: OT: Is this Comeau's real site is is it a phishing scam?

From: noloader@...

Date: Wed, 14 Aug 2013 12:19:47 -0700 (PDT)



Hi All,



Comeau has been offline for some time. Recently, it came back and I'm interested in picking up a copy of their latest compiler.



Though the site is up, its a mess. It looks like something phishers with English as a second language would put up (perhaps the phishers would be a little more professional).



Additionally, the site uses a Paypal account for online transactions. There is talk of accepting checks, but there's no address provided. Perhaps they want a scanned electronic copy?



Finally, they are using a Gmail account rather than a domain account.



Can anyone confirm if this is the real Comeau site? Has anyone done business with Comeau with expected results?



Thanks in advance,

Jeffrey Walton

Baltimore, MD, US









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?65951-OT-Is-this-Comeau-s-real-site-is-is-it-a-phishing-scam&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

safe "struct hack"?

Newsgroup: comp.lang.c++

Subject: safe "struct hack"?

From: Jonathan Lee <jonathan.lee.975@...>

Date: Wed, 14 Aug 2013 06:45:11 -0700 (PDT)



Hello all,

I've have a variation of the struct hack that I think is legal. Wondering if anyone could spot a reason why not. (By struct hack I mean putting a variable length array at the end of a struct, or a struct at the beginning of an array).



Suppose I want to add an int array to the end of



struct header

{

int a;

int b;

double c;

// int arr[]; // I think C99 would do this

}



Then I can make the union



union wrap

{

header hdr;

int arr[1];

}



And use calloc to get some memory



void* p = calloc(20, sizeof(wrap));



The following casts should be legal:

union* u = static_cast<union*>(p);

header* h = static_cast<header*>(u);

int* i = static_cast<int*>(u);



But, then, this should also be legal



int* j = static_cast<int*>(u + 1);



which is an aligned int pointer just past the header

struct. Seeing as how this came from calloc-d, "void"

memory, I think j + 0, j + 1, j + 2, ... are legal

int addresses.



After all, I can legally use



int* q = static_cast<int*>(p);



as an int array. I don't see why j would be any

different.



Can anyone see why this wouldn't be the case?



Thanks in advance,

--Jonathan







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?65663-safe-struct-hack&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
Newsgroup: comp.lang.c++

Subject: Difference between static_cast<const A>(*this) and static_cast<const A&>(*this)

From: junyangzou <zoujyjs@...>

Date: Tue, 13 Aug 2013 07:19:32 -0700 (PDT)



This is an excerpt from "Effective C++" item 03. I add some code to actually make it runnable. And here is the question: I tried to change the static_cast<const TextBook&> to static_cast<const TextBook>, and it runs good. So is there any difference between the two statement.





1 #include <iostream>

2 #include <string>

3

4 using namespace std;

5

6 class TextBook {

7 public:

8 TextBook( std::string name = "" )

9 :text(name){}

10 const char& operator[] ( std::size_t position ) const {

11 return text[position];

12 }

13

14 char& operator[] ( std::size_t position ) {

15 return const_cast<char&>(

16 static_cast<const TextBook&>(*this)[position]

17 );

18 }

19 private:

20 std::string text;

21 };

22

23 int main() {

24 TextBook book("Effective C++");

25 const TextBook book2(book);

26

27 //cout << book[0] << " " << book2[0] << endl;

28 book[0] = 'D';

29 cout << book[0] << endl;

30 return 0;

31 }







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?64717-Difference-between-static_cast(*this)-and-static_cast(*this)&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Conditional compilation oddity

Newsgroup: comp.lang.c++

Subject: Conditional compilation oddity

From: "Norman J. Goldstein" <normvcr@...>

Date: Fri, 09 Aug 2013 21:36:10 -0700



The following program compiles and links.

No warnings The output is wrong, stating:



value= 1

value NOT 1





//////////////////////////////////////////////

#include <iostream>

using namespace std;



static constexpr int value = 1;



int main( int argc, char* argv[] )

{

cout << "value= "

<< value

<< endl;



static_assert( value == 1, "Value_Not_1" );



#if value == 1

cout << "value 1" << endl;

#else

cout << "value NOT 1" << endl;

#endif



return 0;

}// main

/////////////////////////////////////////////////



Why is value not used in the conditional compilation?

(The static_assert is happy.)



I am using

gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)

pn

Linux 3.9.11-200.fc18.i686.PAE #1 SMP







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?63067-Conditional-compilation-oddity&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Tuesday, August 6, 2013

Does standard say anything about pointer->int or int->ptr conversions?

Newsgroup: comp.lang.c++

Subject: Does standard say anything about pointer->int or int->ptr conversions?

From: Peter <pilarp@...>

Date: Mon, 5 Aug 2013 14:44:01 -0700 (PDT)



It's not that uncommon to see code where integral type is cast to a pointer or vice versa. On this page:



https://computing.llnl.gov/tutorials/pthreads/



you can see a few examples of casting void* to long, long to void* etc. Does standard address such conversions in any way other than calling them "undefined behaviour"? If not then why do people use them? Are they well defined for a particular compiler/hardware?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?59018-Does-standard-say-anything-about-pointer-int-or-int-ptr-conversions&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Sunday, August 4, 2013

Does wstream make sense?

Newsgroup: comp.lang.c++

Subject: Does wstream make sense?

From: Daniel <danielaparker@...>

Date: Sat, 3 Aug 2013 20:02:55 -0700 (PDT)



I don't understand it. It seems to be as pointless and outside the spirit of c/c++ io as would be a floatstream or intstream.



Daniel







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?58012-Does-wstream-make-sense&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

History of and support for std::basic_string::back()

Newsgroup: comp.lang.c++

Subject: History of and support for std::basic_string::back()

From: JC <jason.cipriani@...>

Date: Fri, 2 Aug 2013 17:43:27 -0700 (PDT)



For as long as I could remember, basic_string never had a back() member. In a recent discussion somewhere else, I went digging for a C++ standard and found http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf, looking for evidence that back() was indeed not standard in C++.



Yet, it's right there, in 21.4.5.10.



My questions are:



1. Has this always been the case? If so, then why are there so many STL implementations that don't seem to have back()? If not, then when was it added?



2. Most documentation references to back() say "since C++11". Is C++11 an evolution of the C++ standard, reflected in revisions to the C++ specifications? Or is there a separate, distinct "C++11" specification? If the former, where can I find the last version of C++ that wasn't considered C++11?



Thanks!

Jason







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?57420-History-of-and-support-for-std-basic_string-back()&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Friday, August 2, 2013

investigatory project

Newsgroup: comp.lang.c++

Subject: investigatory project

From: hatprab@...

Date: Fri, 2 Aug 2013 07:48:48 -0700 (PDT)



I need a new project idea in c++ for my school because all of the other are very boring topics so can anyone suggest a new one







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?57062-investigatory-project&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Tax Problem C++

Newsgroup: comp.lang.c++

Subject: Tax Problem C++

From: robinhood.biira@...

Date: Fri, 2 Aug 2013 06:55:41 -0700 (PDT)





For the solution, we request that you use C++ We expect your solution to be developed in an Object Oriented approach, and we will be evaluating your Object Oriented Design Skills.

We will be reviewing the SOURCE CODE of your application, and not the UI. We do not expect a fancy web application or windows forms application. A text or console based application would be enough.

You may not use any external libraries to solve this problem, but you may use external libraries or tools for building or testing purposes. Specifically, you may use unit testing libraries or build tools available for your chosen language (e.g., JUnit, Ant, NUnit, Rspec, Rake, etc.)

All problems below require some kind of input. You are free to implement

any mechanism for feeding input into your solution (for example, using hard coded data within a unit test). You should provide sufficient evidence that your solution is complete by, as a minimum, indicating that it works correctly against the supplied test data.

While these are small problems, we expect you to submit what you believe is production-quality code that you would be able to run, maintain and evolve. You don?t need to gold plate- your solution, but we are looking for something more than a bare-bones algorithm.

Optionally, you can include a brief explanation of your design and assumptions along with your code, as well as instructions to run your application.



PROBLEM TWO: SALES TAXES



Basic sales tax is applicable at a rate of 10% on all goods, except books,

food, and medical products that are exempt. Import duty is an additional

sales tax applicable on all imported goods at a rate of 5%, with no

exemptions.



When I purchase items I receive a receipt which lists the name of all the

items and their price (including tax), finishing with the total cost of the

items, and the total amounts of sales taxes paid. The rounding rules for

sales tax are that for a tax rate of n%, a shelf price of p contains

(np/100 rounded up to the nearest 0.05) amount of sales tax.



Write an application that prints out the receipt details for these shopping

baskets...

INPUT:



Input 1:

1 book at 12.49

1 music CD at 14.99

1 chocolate bar at 0.85



Input 2:

1 imported box of chocolates at 10.00

1 imported bottle of perfume at 47.50



Input 3:

1 imported bottle of perfume at 27.99

1 bottle of perfume at 18.99

1 packet of headache pills at 9.75

1 box of imported chocolates at 11.25



OUTPUT



Output 1:

1 book : 12.49

1 music CD: 16.49

1 chocolate bar: 0.85

Sales Taxes: 1.50

Total: 29.83



Output 2:

1 imported box of chocolates: 10.50

1 imported bottle of perfume: 54.65

Sales Taxes: 7.65

Total: 65.15



Output 3:

1 imported bottle of perfume: 32.19

1 bottle of perfume: 20.89

1 packet of headache pills: 9.75

1 imported box of chocolates: 11.85

Sales Taxes: 6.70

Total: 74.68

=========







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?57061-Tax-Problem-C&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

Read data into c++

Newsgroup: comp.lang.c++

Subject: Read data into c++

From: axcytz@...

Date: Thu, 1 Aug 2013 17:17:44 -0700 (PDT)



Hi all,



I have a data that looks like this:



1,2,3

1,3,4

2,4

1

2,4,5,6



I have these data in an excel file but can also copy into a txt file. I have declared a vector in c++ and want to read these data into my c++ code. For small problems, I typed it manually in my c++ code as:



int init1[] = {1,2,3};

std::vector<int> row1( init1, init1+sizeof(init1)/sizeof(init1[0]));

P.push_back(row1);



int init2[] = {1, 3, 4};

std::vector<int> row2( init2, init2+sizeof(init2)/sizeof(init2[0]));

P.push_back(row2);



and so on.



How can I import these data from txt or excel file?



Thanks









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?56461-Read-data-into-c&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums