Osnovne računske operacije

Program "Basic arithmetic operations" je namenjen za izračunavanje četri proste matematičke operacije : sabiranje, oduzimanje, množenje i deljenje. Kao što je navedeno u toku razvoja algoritma ( ^ ), za potrebe programa koriste se varijable 'X' , 'Y' i 'Z' za smeštanje vrednosti promenljivih i rezultata, tipa double, broj koji pripada skupu realnih brojeva , u pokretnom zarezu, s dvostrukom preciznošću pri izračunavanjima. Varijable 'A' i 'B' su pomoćne promenljive koje se koriste prilikom unosa vrednosti promenljivih od strane korisnika tipa string, textualni tip podataka. Ovo je zbog toga jer se u okviru programa koriste funkcije za proveru da li je korisnik ukucao broj iz skupa realnih brojeva, a to se odrađuje na ovom tipu podataka, tako što program posmatra unetu vrednost s tastature kao text , a zatim ga prebaci u brojčanu vrednost pod uslovom da je uneti text broj iz skupa realnih brojeva.Varijabla 'Answer' tipa string se koristi za smeštanje odgovora korisnika na pitanje "Da li hoće opet da pokrene program ?".

Program u odnosu na algoritam sadrži proširenje u smislu dodate tri matematičke operacije ali se u suštini ništa ne menja. Na dnu strane se nalaze prilozi u okviru kojih je i "Basic arithmetic operations open source.zip" arhiva s kompletnim rešenjem pisanim za IDE SharpDevelop C#, koje možete preuzeti i menjati po želji. Neophodan .Net framework 4.0 ili noviji. Tu je takođe i izvršna verzija programa koju možete preuzeti klikom na sliku programa ili na link u okviru priloga.

https://sites.google.com/site/periczeljkosmederevo/Besplatni-programi/osnovne-racunske-operacije/Basic%20arithmetic%20operations.zip?attredirects=0

/************************************************************************************************

* Program name : Basic arithmetic operations *

* Program ver. : 2.0 *

* Created by : SharpDevelop *

* Code author : Perić Željko *

* Code language : C# *

* Date created : 27.01.2012 *

* Time created : 18:41 *

* *

* *

* Program Description : Simple console application to calculate four simple math operations *

* Addition, subtraction, multiplication and division. *

* *

* *

* Program Accuracy Notice : *

* *

* All calculations in program are executed using double type of variable. *

* By default , a double value contains 15 decimal digits of precision , *

* although a maximum of 17 digits is maintained internally. *

* Result is shown in scientific format , rounded at fourteen decimals. *

* This could cause fatal error because , in some cases for accurate result , *

* many more digits are significant , especially when very large or very small *

* numbers are involved. *

* Usually input values that user type in , have it's own precision error... *

* *

* So the result that this program gives is not always 100 % accurate, but approximate. *

* *

* *

* All the best, *

* Author. *

************************************************************************************************/

using System;

namespace Basic_arithmetic_operations

{

class Program

{

public static void Main(string[] args)

{

//

// declaration of variables

//

string A = " ";

string B = " ";

string Answer = "N";

double X = 0;

double Y = 0;

double Z = 0;

bool Number_Relevance = false;

//

// beginning label ,

// marks the point of return in program

// if the user wants to re-start program

// used for 'goto' command

//

beginning :

//

// Set console dimensions , text color , clear console and write Title

//

Console.SetWindowSize(63,33);

Console.Title = "Basic arithmetic operations";

Console.ForegroundColor = ConsoleColor.Green;

Console.Clear();

Console.WriteLine("***************************************************************");

Console.WriteLine(" Program basic arithmetic operations");

Console.WriteLine("***************************************************************");

//

// Get X value from Console

//

A = " ";

Number_Relevance = false;

Console.WriteLine();

Console.WriteLine("Enter value for X : ");

A = Console.ReadLine();

Number_Relevance = double.TryParse(A,out X);

//

// Check whether the entered number belongs to the set of real numbers

// If not re-request the value of X

//

while (Number_Relevance == false)

{

A = " ";

Number_Relevance = false;

Console.WriteLine("Error , You must enter a number. Please enter value for X : ");

A = Console.ReadLine();

Number_Relevance = double.TryParse(A,out X);

}

//

// Get Y value from Console

//

B = " ";

Number_Relevance = false;

Console.WriteLine();

Console.WriteLine("Enter value for Y: ");

B = Console.ReadLine();

Number_Relevance = double.TryParse(B,out Y);

//

// Check whether the entered number belongs to the set of real numbers

// If not re-request the value of Y

//

while (Number_Relevance == false)

{

B = " ";

Number_Relevance = false;

Console.WriteLine("Error , You must enter a number. Please enter value for Y : ");

B = Console.ReadLine();

Number_Relevance = double.TryParse(B,out Y);

}

//

// Clear console for result output and write Title

//

Console.Clear();

Console.WriteLine("***************************************************************");

Console.WriteLine(" Program basic arithmetic operations");

Console.WriteLine("***************************************************************");

Console.WriteLine();

Console.WriteLine(" X = " + X.ToString() + " Y = " + Y.ToString());

//

// Basic arithmetic operations + , - , * , /

// Calculate and write the result

//

//

// Z = X + Y

//

Z = X + Y;

Console.WriteLine();

Console.WriteLine("***************************************************************");

Console.WriteLine();

Console.WriteLine(" Z = X + Y" + " Z = " + X.ToString() + " + " + Y.ToString() + " Z = " + Z.ToString());

Console.WriteLine();

//

// Z = X - Y

//

Z = X - Y;

Console.WriteLine();

Console.WriteLine("***************************************************************");

Console.WriteLine();

Console.WriteLine(" Z = X - Y" + " Z = " + X.ToString() + " - " + Y.ToString() + " Z = " + Z.ToString());

Console.WriteLine();

//

// Z = X * Y

//

Z = X * Y;

Console.WriteLine();

Console.WriteLine("***************************************************************");

Console.WriteLine();

Console.WriteLine(" Z = X * Y" + " Z = " + X.ToString() + " * " + Y.ToString() + " Z = " + Z.ToString());

//

// Z = X / Y

//

// If Y equals zero , dividing by zero is not possible.

// You may try to skip this question , the result is interesting

// from math aspect , if you have adequate scool you should anderstand.

if ( Y != 0 )

{

Z = X / Y;

Console.WriteLine();

Console.WriteLine("***************************************************************");

Console.WriteLine();

Console.WriteLine(" Z = X / Y" + " Z = " + X.ToString() + " / " + Y.ToString() + " Z = " + Z.ToString());

Console.WriteLine();

Console.WriteLine("***************************************************************");

Console.WriteLine();

}

else

{

Console.WriteLine();

Console.WriteLine("***************************************************************");

Console.WriteLine();

Console.WriteLine(" Z = X / Y" + " Z = ?" + " Dividing by zero is not possible ");

Console.WriteLine();

Console.WriteLine("***************************************************************");

Console.WriteLine();

}

//

// The request for an answer , if user wants to start program again.

//

Answer = " ";

Console.WriteLine("Do you want to start the program again <Y/N>");

Answer = Console.ReadLine(); // get the ansver

Answer = Answer.ToUpper(); // set all the letters inside ansver to Upper case

while(Answer != "Y" && Answer != "N")

{

Answer = " ";

Console.WriteLine("Error, answer could only be Y for Yes or N for No !");

Console.WriteLine("Do you want to start the program again <Y/N>");

Answer = Console.ReadLine();

Answer = Answer.ToUpper();

}

if (Answer == "Y")

{

//

// jump to beginning label

//

goto beginning;

}

Console.WriteLine();

Console.Write("Press any key to continue . . . ");

Console.ReadKey(true);

}

}

}

/************************************************************************

* Program Licence : *

* *

* Copyright 2012 , Perić Željko *

* (periczeljkosmederevo@yahoo.com) *

* *

* According to it's main purpose , this program is licenced *

* under the therms of 'Free Software' licence agreement. *

* *

* If You do not know what those therms applies to *

* please read explanation at the following link : *

* (http://www.gnu.org/philosophy/free-sw.html.en) *

* *

* Since it is Free Software this program has no warranty of any kind. *

************************************************************************

* Ethical Notice : *

* *

* It is not ethical to change program code signed by it's author *

* and then to redistribute it under the same name , especially *

* if it is incorrect. *

* *

* It is recommended that if you make improvement in program code , *

* to make remarks of it and then to sign it by Your's name , *

* for further redistribution as new major version of program. *

* *

* Author name and references of old program code version should be *

* kept , for tracking history of program development. *

* *

* For any further information please contact code author at his email. *

************************************************************************/

/************************************

* List Of Revisions *

************************************

* Major revision of version 1.0 *

* Author 25.11.2013 *

* New comments added *

* Program licence changed *

* New version number 2.0 *

************************************/