Ask for program

Discussion in 'C++' started by anewme.fa@gmail.com, May 14, 2013.

  1. Guest

    Who have c++ program that include string,pointer and 2D array?
     
    , May 14, 2013
    #1
    1. Advertising

  2. Guest

    i need the program to be my example...just a simple program that include all of these..
     
    , May 14, 2013
    #2
    1. Advertising

  3. On Mon, 13 May 2013 18:50:10 -0700, anewme.fa wrote:

    > Who have c++ program that include string,pointer and 2D array?


    Here you go. This program meets all your requirements:

    #include <iostream>
    int main()
    {
    char name[1][80];
    std:: cout << "What is your name?" << std::endl;
    std::cin >> name[0];
    std::cout << "Hello, " << *name << std::endl;
    }

    It uses a string, a 2D array and there is even a pointer hidden in there.

    Bart v Ingen Schenau
     
    Bart van Ingen Schenau, May 14, 2013
    #3
  4. osmium Guest

    wrote:
    >> Who have c++ program that include string,pointer and 2D array?


    I don't like the question, I can't see any natural commonality in it. I
    would be inclined to write three little programs and just cobble them
    together with main having something like

    demo1();
    demo2();
    demo3();

    The hardest one is the 2D array. You could look at old Usenet messages or
    the FAQ for C for help. I would start with the FAQ.
     
    osmium, May 14, 2013
    #4
  5. red floyd Guest

    On 5/13/2013 6:50 PM, wrote:
    > Who have c++ program that include string,pointer and 2D array?
    >


    No. Who's on first.

    However, I'm in a good mood. Tell you what I'll do.
    Just post your instructor's email address here, and I'll
    write up the program, and just send it to him directly,
    and save you the trouble.

    Also, you might find a good program here:

    http://www.parashift.com/c -faq-lite/dont-ask-hw-probs.html
     
    red floyd, May 14, 2013
    #5
  6. Guest

    On Tuesday, May 14, 2013 9:50:10 AM UTC+8, wrote:
    > Who have c++ program that include string,pointer and 2D array?


    i have a body mass index program but i dont know where should i put the pointer...im a bit confuse about that..
     
    , May 15, 2013
    #6
  7. Ian Collins Guest

    wrote:
    > On Tuesday, May 14, 2013 9:50:10 AM UTC+8, wrote:
    >> Who have c++ program that include string,pointer and 2D array?

    >
    > i have a body mass index program but i dont know where should i put the pointer...im a bit confuse about that..
    >


    Post what you have and ask for specific help.

    --
    Ian Collins
     
    Ian Collins, May 15, 2013
    #7
  8. Guest

    On Tuesday, May 14, 2013 9:50:10 AM UTC+8, wrote:
    > Who have c++ program that include string,pointer and 2D array?


    here is my codes..would u help me where should i put the pointer?

    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <cmath>
    #include <windows.h>
    using namespace std;

    const int maxUser = 100;
    float w, healthyw, h, BMI, newBMI;
    string BMI_description;
    char name[maxUser][50];
    char description_BMI[7][50]={"severely underweight","underweight","normal","overweight","obese","clinically obese","morbidly obese"};
    float userDetail[maxUser][2];
    int playNum;

    void intro();
    void menu();
    void inputhw();
    void formula();
    void category();
    void desc();
    void healthy();
    void table();
    void ask();
    //void credit();
    void AllUsers();

    int main()
    { system("color 5a");
    intro();
    menu();

    system ("pause");
    return 0;
    }

    void intro()
    {
    int x;

    cout<< "\n ----BMI.CALCULATOR----"<< endl;

    cout << "\n\nEnter your name: ";
    cin >> name[++playNum];

    cout << "\a\a";
    system("cls");
    }

    void menu()
    {
    string opt;

    system("cls");

    cout << "\t\t\tM.E.N.U\n\n"<< endl;
    cout <<"[1]: Calculate your BMI."<< endl;
    cout <<"[2]: Show BMI table."<< endl;
    // cout <<"[3]: View credits." << endl;
    cout <<"[4]: View all users." << endl;
    cout <<"[5]: Logout." << endl;
    cout << name[playNum] << ", please enter your option: ";

    do
    {
    cin >> opt;

    try
    {
    if(opt.length() > 1 || opt[0] < '1' || opt[0] > '5')
    throw opt;
    }
    catch(string opt)
    {
    cout << opt << " is invalid option. Please re-enter: ";
    }
    }
    while(opt.length() > 1 || opt[0] < '1' || opt[0] > '5');


    cout << "\a\a\a";
    system("cls");

    switch(opt[0])
    {
    case '1' : inputhw();break;
    case '2' : table();break;
    //case '3' : credit();break;
    case '4' : AllUsers();break;
    default : main();
    }
    }

    void inputhw()
    {
    cout << "Input your weight (in kg): ";
    do
    {
    cin >> w;
    if (w<0 || w>=600) // must not exceed 600 because the weightest man in the world is 555kg only)
    cout << "Invalid weight. " << name[playNum] << ", please enter your weight again (in kg): ";
    }
    while(w<0 || w>=600);

    cout << "Input your height (in meter): ";

    do
    {
    cin >> h;
    if (h<0 || h>3) // must not exceed 3 because the tallest man in theworld is 2.72)
    cout << "Invalid height. " << name[playNum] << ", please enter your height again (in meter): ";
    }
    while(h<0 || h>3);

    BMI=w/pow(h,2);

    cout << "\a\a\a";
    system("cls");
    category();
    }

    void formula()
    {
    newBMI=healthyw/pow(h,2);
    }

    void category()
    {
    char ans;

    userDetail[playNum][0] = BMI;

    if (BMI < 16.5)
    userDetail[playNum][1] = 0;

    else if (BMI >= 16.5 && BMI < 18.5)
    userDetail[playNum][1] = 1;

    else if (BMI >= 18.5 && BMI < 25)
    userDetail[playNum][1] = 2;

    else if (BMI >= 25 && BMI <= 30)
    userDetail[playNum][1] = 3;

    else if (BMI > 30 && BMI <= 35)
    userDetail[playNum][1] = 4;

    else if (BMI > 35 && BMI <= 40)
    userDetail[playNum][1] = 5;

    else
    userDetail[playNum][1] = 6;

    BMI_description = description_BMI[int(userDetail[playNum][1])];

    cout << fixed << setprecision(2) << name[playNum] <<", you are " << BMI_description << "\nYour BMI is "<< BMI << "." << endl;

    desc();
    healthy();
    ask();
    }

    void healthy()
    {
    int x;
    healthyw=w;
    if (BMI<18.5)
    {
    do
    {
    healthyw++;
    formula();
    }
    while(newBMI<18.5);

    cout<<"\n\nYou should increase your weight becoming at least:\n"<<int(healthyw)<<"kg"<<endl;
    }
    else if (BMI>=25)
    {
    do
    {
    healthyw--;
    formula();
    }
    while(newBMI>=25);

    cout<<"\n\nYou should decrease your weight becoming at least:\n"<<int(healthyw)<<"kg"<<endl;
    }
    }

    void table()
    {
    cout <<" THE BMI TABLE"<< endl;
    cout <<" _____________________________________________________________"<<endl;
    cout <<"| BMI | Rating | Waist Size |"<<endl;
    cout <<"|_________|________________|__________________________________|"<<endl;
    cout <<"| | | < or = to | > or = to |"<<endl;
    cout <<"| | | 40 in. (men) or | 40 in. (men) or|"<<endl;
    cout <<"| | | 35 in. (women) | 35 in. (women) |"<<endl;
    cout <<"| | | | |"<<endl;
    cout <<"| | | | |"<<endl;
    cout <<"| <=18.5 | Underweight | -- | N/A |"<<endl;
    cout <<"|18.5-24.9| Normal Weight | -- | N/A |"<<endl;
    cout <<"|25.0-25.9| Overweight | Increased | High |"<<endl;
    cout <<"|30.0-34.9| Obese | High | Very High |"<<endl;
    cout <<"|35.0-39.9| Obese | Very High | Very High |"<<endl;
    cout <<"| >=40 | Extremely Obese| Extremely High | Extremely High|"<<endl;
    cout <<"|_________|________________|_________________|________________|"<<endl;
    ask();
    }

    void desc()
    {
    if (BMI <= 18.5)
    {
    cout << "\n\nBMI is equal to or less than 18.5 (Underweight)\n";
    cout << "_________________________________________________" << endl;
    cout << "\nA lean BMI can indicate that your weight maybe too low. You should consult your physician to determine if you should gain weight,aslow body mass can decrease your body's immune system, which could lead to ilness."<< endl;
    }

    else if (BMI>=18.5 && BMI<=24.9)
    {
    cout << "\n\nBMI is between 18.5 and 24.9 (Normal)\n";
    cout << "_________________________________________________" << endl;
    cout << "People whose BMI is within 18.5 to 24.9 possess the ideal amount of body weight, associated with living longest, the lowest incidenceof serious ilness, as well as being perceived as more physically attractive than people with BMI in higher or lower ranges."<<endl;
    }

    else if (BMI>=25 && BMI<=29.9)
    {
    cout << "\n\nBMI is between 25 and 29.9 (Overweight)\n";
    cout << "_________________________________________________" << endl;
    cout << "People falling in this BMI range are considered overweightand would benefit from finding healthy ways to lower their weight, such asdiet and exercise. Individuals who fall in this range are at increased risk for a variety of ilnesses."<< endl;
    }

    else if (BMI>=30)
    {
    cout << "\n\nBMI is over 30 (Obese)\n";
    cout << "_________________________________________________" << endl;
    cout << "Individuals with a BMI over 30 are in a physically unhealthy condition, which puts them at risk for serious ilnesses such as heart disease, diabetes, high blood pressure, gall bladder disease, and some cancers.These people would benefit greatly by modifying their lifestyle."<<endl;
    }
    }

    void ask()
    {
    char ans;
    int x;
    cout << "\n\n" << name[playNum] <<", back to Menu? (Y:yes N:no): ";

    do
    {
    cin >> ans;

    if(ans=='Y' || ans=='y')
    {
    cout << "\a";
    menu();
    }
    else if (ans=='N' || ans=='n')
    {
    cout << "\a";

    system("cls");

    cout << "Goodbye, " << name[playNum] << "!\n\n\n" << endl;

    break;
    }
    else
    cout << "Invalid option. Please reenter. Back to menu? (Y/N): ";
    }
    while (ans!='y' && ans!='Y' && ans!='N' && ans!='n');
    }

    void AllUsers()
    {
    int i;

    system("cls");
    cout << "All users that used this program :\n\nNo.\tName\t\tBMI\tDescription\n===\t====\t\t===\t===========\n";

    for(i=1;i<=playNum;i++)
    cout << i << ".\t" << name << "\t\t" << userDetail[0] << "\t"<< description_BMI[int(userDetail[1])] << endl;
    cout << "\n\n";

    system("pause");
    menu();
    }
     
    , May 15, 2013
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. smilebamboo

    ask for help :simulation problem

    smilebamboo, Aug 17, 2004, in forum: VHDL
    Replies:
    3
    Views:
    474
    smilebamboo
    Aug 18, 2004
  2. CM
    Replies:
    0
    Views:
    343
  3. angelayoub
    Replies:
    1
    Views:
    3,696
    Victor Bazarov
    Feb 5, 2004
  4. Replies:
    1
    Views:
    355
    Daniel Pitts
    Sep 19, 2007
  5. Wik
    Replies:
    1
    Views:
    103
    spiralofhope
    Mar 28, 2011
Loading...

Share This Page