Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Руководство_по_C++_CLI.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
8.1 Mб
Скачать

9.3.3Practical Learning: Introducing Functions

1. To see an example of passing arguments to a function, change the file as follows:

#include <iostream>

using namespace std;

using namespace System;

void ShowAppTitle();

void CreateProperty();

void ShowProperty(long propNbr, int cond, Byte levels,

unsigned int beds, float baths,

unsigned int year, __wchar_t style, double value);

long GetPropertyNumber()

{

long propertyNumber;

Console::Write("Property #: ");

propertyNumber = long::Parse(Console::ReadLine());

return propertyNumber;

}

int GetPropertyCondition()

{

Console::WriteLine("Property Condition");

Console::WriteLine("0. Unknown");

Console::WriteLine("1. Excellent");

Console::WriteLine("2. Good (may need minor repair");

Console::WriteLine("3. Acceptable (needs major repair)");

Console::WriteLine("4. Even (land is more important)");

Console::Write("Your Choice: ");

int condition = int::Parse(Console::ReadLine());

return condition;

}

Byte GetNumberOfStories()

{

Byte stories;

Console::Write("Stories: ");

stories = int::Parse(Console::ReadLine());

return stories;

}

unsigned int GetBedrooms()

{

unsigned int bedrooms;

Console::Write("Bedrooms: ");

bedrooms = int::Parse(Console::ReadLine());

return bedrooms;

}

__wchar_t GetPropertyStype()

{

__wchar_t style;

Console::WriteLine("Style");

Console::WriteLine("U. Unknown");

Console::WriteLine("S. Split Level");

Console::WriteLine("C. Colonial");

Console::WriteLine("G. Georgial");

Console::Write("Your Choice: ");

style = __wchar_t::Parse(Console::ReadLine());

return style;

}

double GetPropertyValue()

{

double marketValue;

Console::Write("Market Value: ");

marketValue = double::Parse(Console::ReadLine());

return marketValue;

}

float GetBathrooms()

{

float bathrooms;

Console::Write("Bathrooms: ");

bathrooms = float::Parse(Console::ReadLine());

return bathrooms;

}

unsigned int GetYearBuilt()

{

unsigned int yearBuilt;

Console::Write("Year Built: ");

yearBuilt = int::Parse(Console::ReadLine());

return yearBuilt;

}

int main()

{

Console::WriteLine("To create a listing, enter the

following information");

CreateProperty();

Console::WriteLine();

return 0;

}

void ShowAppTitle()

{

String ^ strTitle1 = L"=//= Altair Realty =//=";

String ^ strTitle2 = L"-=- Properties Inventory -=-";

Console::WriteLine(strTitle1);

Console::WriteLine(strTitle2);

}

void CreateProperty()

{

long propertyNumber;

int condition;

Byte stories;

unsigned int bedrooms;

float bathrooms;

unsigned int yearBuilt;

__wchar_t style;

double marketValue;

ShowAppTitle();

Console::WriteLine("To create a listing, enter the

following information");

propertyNumber = GetPropertyNumber();

condition = GetPropertyCondition();

stories = GetNumberOfStories();

bedrooms = GetBedrooms();

bathrooms = GetBathrooms();

yearBuilt = GetYearBuilt();

style = GetPropertyStype();

marketValue = GetPropertyValue();

system("cls");

ShowAppTitle();

ShowProperty(propertyNumber, condition, stories,

bedrooms, bathrooms, yearBuilt,

style, marketValue);

}