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

9.2.2Practical Learning: Returning a Primitive Type

  1. To create functions that return some values, change the file as follows:  

#include <iostream>

using namespace std;

using namespace System;

long GetPropertyNumber()

{

long propertyNumber;

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

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

return propertyNumber;

}

Int GetPropertyCondition()

{

Int condition;

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: ");

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;

}

Void CreateAndShowProperty()

{

long propertyNumber;

Int condition;

Byte stories;

unsigned int bedrooms;

float bathrooms;

unsigned int yearBuilt;

__wchar_t style;

double marketValue;

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

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

Console::WriteLine(strTitle1);

Console::WriteLine(strTitle2);

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");

Console::WriteLine(strTitle1);

Console::WriteLine(strTitle2);

Console::WriteLine("=//= Property Listing =//=");

Console::WriteLine("Property #: {0}", propertyNumber);

Console::WriteLine("Condition: {0}", condition);

Console::WriteLine("Style: {0}", style);

Console::WriteLine("Bedrooms: {0}", bedrooms);

Console::WriteLine("Bathrooms: {0}", bathrooms);

Console::WriteLine("Stories: {0}", stories);

Console::WriteLine("Year Built: {0}", yearBuilt);

Console::WriteLine("Market Value: {0:C}", marketValue);

}