// tri_over.cpp
// Illustrate overloaded tri_area functions
#include
#include
#include
#include
using namespace std;
double tri_area (double base, double height);
// Base & Height formula
// Area = 1/2 x base x height
double tri_area (double a, double b, double c);
// Hero's Three Sides formula
// Area = Sqareroot [s(s-a)(s-b)(s-c)] where s=a+b+c (i.e. perimeter)
int main()
{
double base, height,
s1, s2, s3,
area;
cout << "Enter base and height of a triangle: ";
cin >> base >> height;
area = tri_area(base,height);
cout << "Area = " << area << endl;
cout << "Enter lengths of sides of a triangle: ";
cin >> s1 >> s2 >> s3;
cout << "Area = " << tri_area(s1, s2, s3) << endl;
system("PAUSE");
return 0;
}
double tri_area (double base, double height)
{double area_bh;
area_bh=(base*height/2.0);
return area_bh;
} // stub
double tri_area (double a, double b, double c)
{ double area_3s, per;
per=((a+b+c)/2);
area_3s=sqrt(per *(per-a)*(per-b)*(per-c));
return area_3s;
}
Journal of computing related issues for Web Authoring, and general topics using Mac, Windows and Linux platforms.
Monday, June 11, 2007
C++ - Hero's Method of Calculating Triangle Area
C++ Program - Identify Pythagoras Triangle
// Pythagoras-03.cpp
/* Listing of right angle triangles with whole number sides e.g. 3 4 5
Need only try possible values below Squareroot of side_1 sqaured + side_2 squared
I want to treat triangle (3 4 5) as a duplicate of (4 3 5)
Achieve this by only selecting results with side_1 > side_2
Also need to remove multiples such as (6 8 10) (12 16 20)
all multiples of (3 4 5).
Do this by seeing if greatest common denominator > 1 by calling
gcd with side-1 and side_2 to find their gcd and then call gcd
again with this gcd and hyp.
If this is 1 then combination is not a multiple
gcd uses Euclidean method to find gcd.
Virtual printer provides an alternative output source for printer
redirecting to D:\\My Documents\\Temp\\VPRINTER.OUT.
I use this as the console does not keep all of output in lon runs.
You can comment it out if you wish.
*/
#include
#include
#include
#include "D:\My Documents\Borland Studio Projects\mytools.h"
// #include "C:\Documents and Settings\Rod Talboys\My Documents\Borland Studio Projects\mytools.h"
void get_range (int& min, int& max); //out
int gcd (int a, int b); // in-out
void main()
{
// Virtual printer
// This file provides an alternative output source for printer
ofstream vprn ("D:\\My Documents\\Temp\\VPRINTER.OUT");
int max, min, side_1, side_2, hyp, count;
int hypmax, hypmin;
get_range (min, max);
cout << "Pythagorean triangles between " << min << " and " << max << endl;
vprn << "Pythagorean triangles between " << min << " and " << max << endl;
count=0;
for (side_1=min;side_1<=max;side_1++)
{
for (side_2=min;side_2<=max;side_2++)
{
// check if side_1*side_1 + side_2*side_2 is perfect square
// establish hypmin and hypmax
if (side_1>side_2) (hypmin=side_1);
else (hypmin=side_2); // removes surplus
hypmax= floor(sqrt(side_1*side_1 + side_2*side_2)); // processing
for (hyp=hypmin;hyp<=hypmax;hyp++)
{
if ((hyp*hyp==(side_1*side_1 + side_2*side_2))&& (side_1 < side_2))
{
if ((gcd ( hyp, gcd (side_1, side_2))) == 1)
{
cout << side_1 << " " << side_2 << " " << hyp << endl;
vprn << side_1 << " " << side_2 << " " << hyp << endl;
count++ ;
}
}
}
}
}
cout << "There are " << count <<" Pythagorean triangles between " << min << " and " << max << endl;
vprn << "There are " << count <<" Pythagorean triangles between " << min << " and " << max << endl;
system("PAUSE");
return 0;
}
void get_range (int& min, int& max) //out
{
bool valid; // valid for input and prime for prime number
valid = false; // initialise values
max = 0;
while (!valid)
{
cout << "Enter min and max (less than 1,000) values for smaller sides: " << endl;
cin >> min >> max;
if (max > min && max <= 1000)
valid = true;
else
cout << " Invalid entry try again." << endl;
}
}
int gcd (int a, int b)
// Use the Euclidean algorithm to calculate and
// return the greatest common divisor of a and b.
{
int r;
a = labs(a); b=labs(b);
while (b>0)
{ r = a%b; a = b; b = r; }
return a;
}
C++ Programming
I have for years (about 38!) fiddled about with programming. First time was at Rolls Royce in 1968 when bored I played around with a machine about 20x6x4 inches in size programming it to solve quadratic equations.
Then in 1974 I joined IBM as a Systems Engineer (technical marketeer who kept the salesman on this planet - BTW I ended up as a salesman myself) where they taught me to write Assembler. Shame they did not teach me how to get the programs to work. Then had a play around with high level language PL1, good language but did not last. I even taught a class on CICS/VS (don't ask) programming.
So now retired with time to have another play especially as there is a wealth of free compilers, development environments, tutorials and documentation all at the end of broadband. For someone who started writing programs by using coding sheets which were sent to punch room (arghh - nice girls though) and then booking computer time feeding the cards in waiting for the compilation report, correct errors and send back to punch room so the new cards would be ready to do to do the same cycle next day. Today seems like sc-fi has become reality.
I decided to start with C++ and learn enough to be able to code a few sample mathematical exercises because .... strange as it may seem .... I wanted too.
First to select a reasonable, free, compiler that preferably work on Linux too, my longer term target environment. I looked at both Borland Turbo C++ and MS Visual C++, both worked but environment too sophisticated for my immediate needs as I want to be able to understand what is going on.
So I am using Bloodshed Dev-C++ which you can find at http://www.bloodshed.net/devcpp.html
and so far this has been fine.
To get me started I am reading "Using C++" by Julien Hennefeld and CharlesBurchard. It assumes you know little and approaches C++ from a traditional background of code examples and does not introduce Objects until mid way through book. It is published by PWS and its web pages seem to have disappeared so at first I could not get code examples but I found a site St Edwards who have put all the code up on their web pages at http://myweb.stedwards.edu/laurab/bookcode/
For online C++ Reference I currently use
Then in 1974 I joined IBM as a Systems Engineer (technical marketeer who kept the salesman on this planet - BTW I ended up as a salesman myself) where they taught me to write Assembler. Shame they did not teach me how to get the programs to work. Then had a play around with high level language PL1, good language but did not last. I even taught a class on CICS/VS (don't ask) programming.
So now retired with time to have another play especially as there is a wealth of free compilers, development environments, tutorials and documentation all at the end of broadband. For someone who started writing programs by using coding sheets which were sent to punch room (arghh - nice girls though) and then booking computer time feeding the cards in waiting for the compilation report, correct errors and send back to punch room so the new cards would be ready to do to do the same cycle next day. Today seems like sc-fi has become reality.
I decided to start with C++ and learn enough to be able to code a few sample mathematical exercises because .... strange as it may seem .... I wanted too.
First to select a reasonable, free, compiler that preferably work on Linux too, my longer term target environment. I looked at both Borland Turbo C++ and MS Visual C++, both worked but environment too sophisticated for my immediate needs as I want to be able to understand what is going on.
So I am using Bloodshed Dev-C++ which you can find at http://www.bloodshed.net/devcpp.html
and so far this has been fine.
To get me started I am reading "Using C++" by Julien Hennefeld and CharlesBurchard. It assumes you know little and approaches C++ from a traditional background of code examples and does not introduce Objects until mid way through book. It is published by PWS and its web pages seem to have disappeared so at first I could not get code examples but I found a site St Edwards who have put all the code up on their web pages at http://myweb.stedwards.edu/laurab/bookcode/
For online C++ Reference I currently use
- C++ QUICK REFERENCE summary http://sourcepole.ch/sources/programming/cpp/cppqref.html
- cplusplus for in depth reference at http://www.cplusplus.com/info/
Wednesday, April 18, 2007
QUANTA PLUS Web Developer SUSE 10.2
If you are looking for above in SUSE 10.2 then checkout http://www.mail-archive.com/opensuse@opensuse.org/msg31380.html
Quanta is in the package "kdewebdev3". If I remember correctly I went to Applications->System->Configure->Install Software
and located "kdewebdev3", selected it and ran install. It asked for the CD 5(?), I inserted DVD I had from Linux Mag with SUSE 10.2 install on it, it found software and all ok.
and located "kdewebdev3", selected it and ran install. It asked for the CD 5(?), I inserted DVD I had from Linux Mag with SUSE 10.2 install on it, it found software and all ok.
(Note I have 2 "Install Software" I chose the 2nd)
Note I just tried to repeat this before writing blog and could not find "kdewebdev3" I guess having been installed it is removed from Available list.
Linux Windows Equivalent Programs
There are some key applications I use in my Windows system that will need to be matched with Linux equivalent. Here is the results of my studies to date, note I am only listing programs of interest to me.
Common - versions for both Linux and Windows
This does not mean that there is none, just I have not either found them or decided yet
Common - versions for both Linux and Windows
- OpenOffice (Opensource Office Suite - so good I did not install MS Office on new PC)
- Picasa photo viewer and entry editor
- Firefox web browser
- GIMP - Photoshop type program - currently getting to grips with this
- Googlemail
- Google "Office"
- NotepadPro editor and HTML builder
-> KATE as editor QUANTA PLUS as HTML builder - Photoshop Elements (mainly used to catalogue my photos currently 16,000+)
-> F-Spot Great news is that if you save Tag information to file in PSE then when you Import into F-Spot the Tag information is automatically loaded.
This does not mean that there is none, just I have not either found them or decided yet
- SERIF PagePlus - Publisher application
- SERIF WEBPlus - High function web developer
- SERIF MOVIEPlus - High function but complicated movie editor
- PDA synchroniser
- Mediaplayer
- CD/DVD writer
- FTP
- DivX MP4 support
Monday, April 9, 2007
Linux SUSE 10.2 VM accessing Windows Files of Host
From previous posts you will see that I have set up a SUSE 10.2 Guest within my Windows XP system using VirtualBox on my Notebook. Also I have managed to access XP files on my home network from my native SUSE 10.2 PC, By combining the methods I can access XP files on my Notebook from within SUSE guest.
Enter smb://192.168.1.3 and it gave me access to "My Documents" which I have setup as shared. The address of my PC (192.168.1.3) I found this time by using MS "System Information" found by following
Start->All Programs->Accessories->System Tools and then from within "System Information" follow System Summary->Components->Network->Adapter and in my case used IP address found in wireless.
Enter smb://192.168.1.3 and it gave me access to "My Documents" which I have setup as shared. The address of my PC (192.168.1.3) I found this time by using MS "System Information" found by following
Start->All Programs->Accessories->System Tools and then from within "System Information" follow System Summary->Components->Network->Adapter and in my case used IP address found in wireless.
Monday, April 2, 2007
Linux SUSE 10.2 via VirtualBox on Laptop
Well at last I have a Linux system coexisting with my Windows XP and connecting to web through wireless without having to change XP system, especially boot options. See previous post
It was not without problems and some problems appeared to "heal" themselves. I will add more info when time permits.
Note, this entry is being typed into Google Blogger, in Firefox, in SUSE 10.2, running as virtual machine under control of VirtualBox within MS XP on my Fujitsu Siemens Amilo Notebook and through wireless connection to GURU ADSL router/modem into Orange Broaband.
It was not without problems and some problems appeared to "heal" themselves. I will add more info when time permits.
Note, this entry is being typed into Google Blogger, in Firefox, in SUSE 10.2, running as virtual machine under control of VirtualBox within MS XP on my Fujitsu Siemens Amilo Notebook and through wireless connection to GURU ADSL router/modem into Orange Broaband.
Subscribe to:
Posts (Atom)
Blog Archive
About Me
- Rod T
- Husband, dad and grandad. Physics graduate from London University in late 60s. Retired from IBM company in 2000 after 27 years as both Sytems Engineer and Salesman. Interests include photography, nature, science, maths, walking, travel. I like facts as a basis of opinion and not opinion that is assumed to be fact.