Click here to Skip to main content
15,913,939 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionA question about compound document and flat document Pin
code_chenyf7-Sep-05 17:29
code_chenyf7-Sep-05 17:29 
QuestionHow to get all the frames of a web page(CHtmlView)? Pin
Tcpip20057-Sep-05 16:48
Tcpip20057-Sep-05 16:48 
AnswerRe: How to get all the frames of a web page(CHtmlView)? Pin
Tcpip20057-Sep-05 16:52
Tcpip20057-Sep-05 16:52 
GeneralRe: How to get all the frames of a web page(CHtmlView)? Pin
Hans Ruck7-Sep-05 20:28
Hans Ruck7-Sep-05 20:28 
GeneralRe: How to get all the frames of a web page(CHtmlView)? Pin
Tcpip20057-Sep-05 20:32
Tcpip20057-Sep-05 20:32 
GeneralRe: How to get all the frames of a web page(CHtmlView)? Pin
Hans Ruck7-Sep-05 20:35
Hans Ruck7-Sep-05 20:35 
AnswerRe: How to get all the frames of a web page(CHtmlView)? Pin
Ralf Martin Hansen3-Apr-24 21:05
Ralf Martin Hansen3-Apr-24 21:05 
QuestionHelp please can someone rewrite this Pin
SummoningDan7-Sep-05 16:33
SummoningDan7-Sep-05 16:33 
can someone please rewrite this program using a class in a .h file


#include<iostream>
#include<fstream>
#include<string>

using namespace std;

const int MAX_PROPERTIES = 50;

struct property
{
string address;
string suburb;
int price;
};

int readFile(property properties[]);
int menu();

void listAll(property properties[], int items);
void search(property properties[], int items);
void addProperty(property properties[], int &items);
void saveProperties(property properties[], int items);

int main()
{
int option = 0;
bool done = false;
int items = 0;

property properties[MAX_PROPERTIES];

items = readFile(properties);

do
{
option = menu();

switch (option)
{
case 1: listAll(properties, items); break;
case 2: search(properties, items); break;
case 3: addProperty(properties, items); break;
case 4: saveProperties(properties, items); break;
case 5: done = true; break;

default: cout << "Illegal menu option" << endl;
}

} while(!done);

return 0;
}

//
// Read the property listing file
//
int readFile(property properties[])
{
string filename;
string remainder;
int items = 0;

cout << "Enter property filename: ";
cin >> filename;
getline(cin, remainder);


ifstream fin(filename.c_str());

if (!fin.is_open())
{
cout << "File \""<< filename << "\" does not exist" << endl << endl;
exit(1);
}


for (int i = 0; i < MAX_PROPERTIES && fin.peek()!= -1; i++)
{
getline(fin, properties[i].address);
getline(fin, properties[i].suburb);
fin >> properties[i].price;
getline(fin, remainder);
cout << properties[i].address << " " << properties[i].suburb
<< " " << properties[i].price << endl;

items++;
}

fin.close();

return items;
}

//
// Display the menu
// Returns the user selction
//
int menu()
{
int option;

cout << endl;
cout << "Menu:" << endl;
cout << "1 - List all properties" << endl;
cout << "2 - Property search" << endl;
cout << "3 - Add a property" << endl;
cout << "4 - Save property list" << endl;
cout << "5 - Exit" << endl << endl;

cout << "Please enter option: ";
cin >> option;

string remainder;
getline(cin, remainder);

cout << endl;

return option;
}

//
// Display all properties in the current listing
//
void listAll(property properties[], int items)
{
for (int i = 0; i < items; i++)
{
cout << "$" << properties[i].price << " ";
cout << properties[i].address << " ";
cout << properties[i].suburb << endl;
}
}

//
// Search for properties up to a maximum price
//
void search( property properties[], int items )
{
int limit;

cout << "Please enter price limit: $";
cin >> limit;

cout << endl;

for (int i = 0; i < items; i++)
{
if (properties[i].price <= limit)
{
cout << "$" << properties[i].price << " ";
cout << properties[i].address << " ";
cout << properties[i].suburb << endl;
}
}
}

//
// Add a property to the current listings without saving to file
//
void addProperty(property properties[], int &items)
{
if (items == MAX_PROPERTIES)
{
return;
}

cout << "Enter address: ";
getline(cin, properties[items].address);

cout << "Enter suburb: ";
getline(cin, properties[items].suburb);

cout << "Enter price: $";
cin >> properties[items].price;

cout << endl << "Property: " << properties[items].address;
cout << " " << properties[items].suburb;
cout << " at $" << properties[items].price;
cout << " added to list" << endl;

items++;
}

//
// Save the current property listing to a file
//
void saveProperties(property properties[], int items)
{
string filename;

cout << "Enter filename: ";
cin >> filename;

ofstream fout(filename.c_str());

if (!fout.is_open())
{
cout << "File \""<< filename << "\" does not exist" << endl << endl;
return;
}

for( int i = 0; i < items; i++ )
{
fout << properties[i].address << endl;
fout << properties[i].suburb << endl;
fout << properties[i].price << endl;
}

cout << "Property details saved to file \"" << filename << "\"" << endl;

fout.close();
}

could you please prewrite this and post the complete .ccp and .h (containg the class)

-- modified at 22:33 Wednesday 7th September, 2005
AnswerRe: Help please can someone rewrite this Pin
PJ Arends7-Sep-05 16:51
professionalPJ Arends7-Sep-05 16:51 
AnswerRe: Help please can someone rewrite this Pin
Marc Soleda7-Sep-05 20:40
Marc Soleda7-Sep-05 20:40 
QuestionThe PlaySound Function Pin
Mr. Bombastic7-Sep-05 15:30
sussMr. Bombastic7-Sep-05 15:30 
AnswerRe: The PlaySound Function Pin
Christian Graus7-Sep-05 15:42
protectorChristian Graus7-Sep-05 15:42 
QuestionGet a file icon for a given file type... Pin
Ian Bowler7-Sep-05 13:21
Ian Bowler7-Sep-05 13:21 
AnswerRe: Get a file icon for a given file type... Pin
Gary R. Wheeler7-Sep-05 14:32
Gary R. Wheeler7-Sep-05 14:32 
GeneralRe: Get a file icon for a given file type... Pin
Ian Bowler8-Sep-05 7:42
Ian Bowler8-Sep-05 7:42 
AnswerRe: Get a file icon for a given file type... Pin
Graham Bradshaw7-Sep-05 14:33
Graham Bradshaw7-Sep-05 14:33 
GeneralRe: Get a file icon for a given file type... Pin
Ian Bowler8-Sep-05 5:48
Ian Bowler8-Sep-05 5:48 
AnswerRe: Get a file icon for a given file type... Pin
David Crow8-Sep-05 3:22
David Crow8-Sep-05 3:22 
Questionprogram step into non defined area Pin
valerie997-Sep-05 12:25
valerie997-Sep-05 12:25 
AnswerRe: program step into non defined area Pin
zildjohn017-Sep-05 12:38
zildjohn017-Sep-05 12:38 
AnswerRe: program step into non defined area Pin
MailtoGops8-Sep-05 3:01
MailtoGops8-Sep-05 3:01 
QuestionAfxEndThread Pin
Anonymous7-Sep-05 12:23
Anonymous7-Sep-05 12:23 
AnswerRe: AfxEndThread Pin
ThatsAlok7-Sep-05 18:57
ThatsAlok7-Sep-05 18:57 
AnswerRe: AfxEndThread Pin
David Crow8-Sep-05 3:24
David Crow8-Sep-05 3:24 
Questiontemplates question Pin
zildjohn017-Sep-05 12:09
zildjohn017-Sep-05 12:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.