Bench 212 Posting Pro

#include "stdafx.h"

On a different subject, you may be pleased to know that you can disable precompiled headers in MSVC++ 2003 (And probably 2005 too, although i've never used 2005) - right click on your project in the solution explorer window, and choose "properties"

in the left-hand pane of the properties window, expand on the item/folder called C/C++

From the list of C/C++ options, choose "Precompiled headers"

Go to the right-hand pane now, and change the option to "Not Using Precompiled Headers"

the 2 boxes beneath can be cleared and left blank

press "OK".

Now you will not get the error when you compile your project without stdafx.h

Bench 212 Posting Pro

Could I have an hint for the buy 4 get 1 free and After 10 adult tickets

Think back to primary school mathematics - Think about the calculation you would do, to work out how many free tickets you would get when you buy 10.

Hint - C++ has the "divide by" operator / ... which on integers returns only the whole number. Any remaining 'fractions' are lost.
For the remainder, use the "modulus" operator %

Bench 212 Posting Pro

I like that but never done it , could you explain in detail?

a User Defined Type (UDT for short) would be either a struct, union, class or enum.. Stay away from unions unless you have any good reason to use one, and enums are for numerical values, which leaves you with struct and class (Note - class is C++ only).

in C++, struct and class are both actually the same thing... well, almost.. they have one minor difference which isn't important at the moment.

a struct (the name originally came from 'data structure') is conceptually very similar to a table layout in an MS Access database - in fact, I suspect that most databases use the term "data structure" too.

At the basic level, it will typically contain one or more "fields" (called member variables), and every record (object) created has its own value for each of these fields.

eg,

struct MyStruct
{
    std::string foreame;
    std::string surname;
    char middleInitial;
    int age;
}

int main()
{
    MyStruct MyPerson;
    MyPerson.forename = "Fred";
    MyPerson.surname = "Bloggs";
    MyPerson.middleInitial = 'E';
    MyPerson.age = 36;
    // etc.
}

You can make an array of UDTs in exactly the same way as you'd create an array of int or any other built-in type. ie,

MyStruct PeopleDatabase[50];
PeopleDatabase[0].forename = "Joseph";

Note - above is C++ code, C uses a slightly different syntax for creating an object of MyStruct. If you are using C++, then this is probably your first step into …

Bench 212 Posting Pro

damn, double-post! see below.

Bench 212 Posting Pro

Doh!

Ok, It looks as though I only have one more error to work around.

84 'EnterNumberOfStudents' undeclared (first use this function)

do{
EnterNumberOfStudents;
}while (!(iNo >= 0 && iNo <= 20));
for(int j=0; j<iNo; j++)
{
Students[j].ReadRecord();
}

EnterNumberOfStudents was your goto tag wasn't it? the compiler is telling you that it doesn't exist (because you've sensibly decided not to use the dreaded 'goto')

from your original code, I believe this is what you wanted to put inside your do-while loop...

cout<<"Enter No of Students between(0 to 20): Enter 0 to Exit";
cin>>iNo;
Bench 212 Posting Pro

In function `int main()':

83 `Do' undeclared (first use this function)

83 expected `;' before '{' token

Are the errors I'm receiving.

"do" is case sensitive.. you used a capital letter D.

Bench 212 Posting Pro

Both the OP and the 1st reply could benefit from this link
http://www.parashift.com/c++-faq-lite/friends.html

Bench 212 Posting Pro

This isn't essential, but I'd recommend using "double" instead of "float" - the reason being that float has very low precision... you may end up with your results being incorrectly rounded... double means "double precision" - which is much more accurate

//getdata gets the days absent by using call by reference
//nothing is returned, nor do hyou need to give it values.
void getdata (float *days out, float *total, float *average, char name[40])

"days out" is not a valid variable name, you can't use spaces. call it something like DaysOut or days_out instead.

{
cout << "enter name ";
cin >> name;
cout << "enter days absent ";
cin >> days absent;

again - "days absent" is an error - there's a space in it. Also, you didn't call it "days absent", you called it "days out"

if (argc > 1)
{
cout << "Total:\n";
for (int count = 1; count < argc; count++)
cout << argv[count] << endl;
}

I don't know why you are doing this, but OK.

float calculattoal(float(total)

Take away the second curvy bracket ( - it should read (float total)

float calcaverage(float total)
{
float average
average=total/employees;
return(total);
}

Are you sure you want to return total? I think you want to return average.

void outputvalues (char name[], float total, average)
{
cout <<name<< "days absent"<<total<<" total and "<<average<<" average"<<endl;

Bench 212 Posting Pro

im not sure exactly what its called or how to use it.. but im guessing its used to pass over variables as arguments to a function, ive only seen it in functions with this added after it: ,...) somewaht similar to the code below..

int myfunc(char *data,const char *data2[B],...[/B])
{
    ....
    return 0;
}

int main(void)
{
    char varhold[21];
    memset(varhold,0,sizeof(varhold));
    sprintf(varhold,"bob");
    myfunc("hey","hi %s",varhold);
    return 0;
}

can someone tell me what it is? how to use it? examples?

The 3 dots "..." are not part of C or C++. Presumably whichever book you are using is obscuring some of the function's definition... It might mean that whatever would be behind those 3 dots is unimportant to the example in your book, but that is just as guess

Bench 212 Posting Pro

1. A program prompts the user on the screen to enter a number below 100,

Here is your first chunk of potential psuedo code, including a clue as to which data type you need.

then display a count on the screem.

here's another bit of potential psuedo code

from 1 to the number entered by the user. For example, if a user enters 12, the screen displays 1 2 3 4 till 12. Write the input,output and pseudocode logic for this problem. what formula would u use for this? cant figure out at all

You should research Looping (also known as recursion) in your text book, or on google. C++ has 3 basic kinds of loops, one of which is suited perfectly to your problem. also, read up on the "increment" operator.

Bench 212 Posting Pro

not necesary that main() should return int. main() is also like normal function you can specify the return type of the main()
santu

No - The C++ standard requires that main() returns an int. You may be lucky (or unlucky) and have a compiler which accepts code where main() returns some other type, without throwing any warnings or errors. But well-formed code always returns an int from main()
Anything other than int can result in undefined/unpredictable behavior

Bench 212 Posting Pro

What code did you try? what couldn't you figure out?

Bench 212 Posting Pro

void main(){

no, no, no! main() returns an int! :(

Bench 212 Posting Pro

the quick 'n' dirty way to display a file is totally un-C++ related. if you are on WIN32, use the MSDOS command "more", ie

system("more < asciiart.txt");
Bench 212 Posting Pro

My book of C++ programming says that, "The relational operators can be applied to variables of type string. Variables of the type string are compared character-by-character, starting with the first character" (C++ Programming: From Problem Analysis To Program Design, Malik, Page 148)
Randy

Correct, however, this isn't what the code is doing - s[5] returns a char and not a std::string.

"W" with double quotes is of type const char* (a pointer to the first element of a string literal)

if you were to do s[5] == 'W' then this comparison would be ok. The difference being that 'W' with single quotes is also of type char.

Bench 212 Posting Pro

unless you're running a prehistoric computer, 10000 is nothing :) you want to be thinking in terms of millions if you wish to obtain a calculatable time difference.

Bench 212 Posting Pro

>
This has nothing to do with C++ since you've shown that you can do a simple string search. At this point it's a problem solving issue. I personally don't think it's terribly difficult to do this:

if ( strstr ( array, "hello my" ) != NULL )
  ++test;
if ( strstr ( array, "hellomy" ) != NULL )
  ++test;
etc...

And since you're probably new to programming, it's unlikely that you'll have an easy time working with regular expressions.

That is a "C" way of doing things, which is fine :)

Here is one method which is a bit more C++... (Yes OK, it is actually a bit more difficult than Narue's method)

int count(0);
    std::string::const_iterator iter(LineIn.begin());

    while(iter != LineIn.end() )
    {
        iter = std::search(LineIn.begin(), LineIn.end(), 
                           match.begin(), match.end() );
        if (iter != LineIn.end() )
        {
            ++count;
            ++iter;
            std::string s(iter, LineIn.end());
            LineIn=s;
        }
        
    }

LineIn is a std::string - using getline() from a file
match is a std::string - the string to match, eg, "hello my"

This method will not ignore whitespace, and will find multiple matches per string.
Although be careful to make sure that the strings are an exact match, ie, "Hello" != "hello" != "HELLO" != "HeLlO" .. etc.

the easy way around the mismatched strings is to change LineIn and match both 'tolower' (or 'toupper' - whichever floats your boat)

Bench 212 Posting Pro

i have a case study....
my prof said that we should display 10 random numbers without reaping the same number for example the screen will print numbers from 0-9 at this order

1 6 7 5 2 3 4 9 8 0

then when we exit the program it should pritn another random number... plss help i needed it very badly :sad: :sad: :sad:

tanx...

OK... so, show us how far you've gotten with your program...

Bench 212 Posting Pro

struct menuList //Define struct menuList with members
{
string Eggs;
string BaconandEggs;
string Muffin;
string FrenchToast;
string FruitBasket;
string Cereal;
string Coffee;
string Tea;
string price:
};

What are these variables supposed to contain? I suspect that you do not want to write out your complete menu in a struct, that would achieve very little except for a very long tedious program.
Remember: a struct is like a template for the type of information you want to store - Do not pre-empt the actual data it is going to contain!

Also, I suspect you want to use a numerical type for price.

void getData();
void showMenu();
void printcheck();

OK - here you have 3 forward declarations of functions, but their definitions are inside your main() function - this is wrong, they must be declared outside main(), either before or after it.

menuItemList.Eggs; //Access a struct member components

This line is doing nothing, letalone accessing anything, what do you intend this line to do?

menuItemList.price = 0.0;

This is an error. assuming you mean "menuItem price" - its a string - you must change price to float, or preferably, double to do this.

void showMenu();
cin >> menuItemType.Eggs >> menuItemType.BaconandEggs;
cin >> menuItemType.Muffin;
cin >> menuItemType.FrenchToast;
cin >> menuItemType.FruitBasket;
cin >> menuItemType.Cereal;
cin>> menuItemType.Coffee;
cin >> menuItemType.Tea;

I Already mentioned that this function must be declared outside main(). Aside …

Bench 212 Posting Pro

thnks for your repy bench i will do the code part if u can help me plz do hlp me in this i cant understand how i will Show a complete class diagram against the system described above.
i hope u will help me.

The class diagram should be easy - it is just a paper representation of your program's basic structure, using graphical and/or psuedo-code. Read what I said above about writing a list of all your different "types" of people, and all the different attributes you need to store (your assignment has it all written down for you, you just need to read it)

Take, for example, a diagram involving modes of road transport - You need to know some information about all types of transport, like what's the vehicles manufacturer & model? for specific types, like a Car, you want to know about it's engine - although Bicycles don't use engines, but Bicycles will have Reflectors on them to make them more visible

[B]Vehicle[/B] - [I]Base Class[/I]
[list]
[*]People_Capacity
[*]Manufacturer
[*]Model_Number
[/list]
[B]Car[/B] - [I]Derived from Vehicle[/I]
[list]
[*]Num_Of_Doors
[*]Engine_Size
[/list]
[B]Bicycle[/B] - [I]Derived from Vehicle[/I]
[list]
[*]Frame_Type
[*]Num_Of_Reflectors
[/list]

You should also include functions, for example, the base class could have a Change_Gear() function, as both Bicycles and Cars use gears - however, only Cars might have a Start_Engine() function.

Bench 212 Posting Pro

in C++, I always try to use library functions, thereby avoiding potentially haphazard loops. for example:

void FindEat(std::string in)
{
    std::string match("eat");
    if (match==in)
        std::cout << "Match found \n" ;  
}

int main()
{
    std::ifstream verbs("verbs.txt");
    if (verbs)
    {
        std::istream_iterator<std::string> start(verbs), finish;
        std::for_each(start, finish, FindEat);
    } else
        std::cout << "error!";
    return EXIT_SUCCESS;
}
Bench 212 Posting Pro

hi comwizz ;) ,
n hi 2 every1 else readin d reply :) . m a new member in the club.i dont get exactly wat u hve typed.... but i see in the foll code u has used j as a variable n incremented i... so look out..
/*
for(j=0;j<l_no;i++)
{
*/

A good way to avoid these sorts of bugs is to only declare the loop variable at the point you actually need to use it.
As far as I can see, the program does not need j anywhere outside the scope of the for loops in which it is used.

one remedy could be

for (int j=0; j<l_no; j++)  {}
SpS commented: Good:sunny +1
Bench 212 Posting Pro

Design and implement a class hierarchy for any organization, employees. We are interested in modeling only the Managers and Faculty. Director shall be treated as a Manager. The following information for each employee needs to be captured:

This is the sort of problem usually given to 1st-year students.
Not to say that means it's a total no-brainer, but come on, do a bit of reading! you've been given all the information on a nice big round plate, you just need to work those brain cells a little to seperate it out.

First Name, Middle Initial, and Last Name
All of above are of type string except Middle Initial that is of type Character.

Have you done any database work? Imagine you are setting up an MS Access database, you will find the data relationship diagram is just the same! You've just been given 3 field names (variables) here... field names/variables are like attributes of your Objects (in this case, Objects are people..)

All Managers belong to certain Level which are numbered 3 through 5 and
all managers must belong to one of the university department (a string).
Director, though Manager, does not belong to any level and also does not belong
to any department. Each faculty member is either professor, Associate or
Assistant Professor and belongs to some department.

Here are more fields/attributes.. and also clues as to what sort of classes/people you should be thinking about..

We are only interested …