Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Ask for program

Reply
Thread Tools

Ask for program

 
 
anewme.fa@gmail.com
Guest
Posts: n/a
 
      05-14-2013
Who have c++ program that include string,pointer and 2D array?
 
Reply With Quote
 
 
 
 
anewme.fa@gmail.com
Guest
Posts: n/a
 
      05-14-2013
i need the program to be my example...just a simple program that include all of these..
 
Reply With Quote
 
 
 
 
Bart van Ingen Schenau
Guest
Posts: n/a
 
      05-14-2013
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
 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      05-14-2013
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.


 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      05-14-2013
On 5/13/2013 6:50 PM, (E-Mail Removed) 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-lit...-hw-probs.html


 
Reply With Quote
 
anewme.fa@gmail.com
Guest
Posts: n/a
 
      05-15-2013
On Tuesday, May 14, 2013 9:50:10 AM UTC+8, (E-Mail Removed) 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..
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-15-2013
(E-Mail Removed) wrote:
> On Tuesday, May 14, 2013 9:50:10 AM UTC+8, (E-Mail Removed) 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
 
Reply With Quote
 
anewme.fa@gmail.com
Guest
Posts: n/a
 
      05-15-2013
On Tuesday, May 14, 2013 9:50:10 AM UTC+8, (E-Mail Removed) 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[i] << "\t\t" << userDetail[i][0] << "\t"<< description_BMI[int(userDetail[i][1])] << endl;
cout << "\n\n";

system("pause");
menu();
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python-noob - which container is appropriate for later exportinginto mySql + matplotlib ? someone Python 45 04-15-2013 12:28 PM
GCC warnings for comma operator W Karas C Programming 16 04-12-2013 08:03 AM
Re: Message passing syntax for objects | OOPv2 Mark Janssen Python 1 04-12-2013 05:22 AM
Re: Message passing syntax for objects | OOPv2 Ethan Furman Python 0 04-12-2013 02:13 AM



Advertisments