-
July 6th, 2018, 03:34 PM
#1
How to use C++ concept I have learned with Visual Studio... visually?
I am learning C++. It is going really well. It is making other stuff I have done in programming really make sense. I was interested in getting started programming with C++ visually. I want to make a program that runs on Windows. I did not know where to get started. There is not a lot of info on the topic. I found a helpful video on YouTube that showed how to get set up. It leaves me off with code like so:
Code:
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThreadAttribute]
int main(array<String^>^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Lotto1::MyForm form;
Application::Run(%form);
return 0;
}
I do not know how to continue from here. How would I add some code that performs something like calculating with overloaded functions! If anybody has any examples I would greatly apreciate seeing them. I want to make a program that calculates values for a sphere or a cylinder with an overloaded function like so:
Code:
int main()
{
double Pi = 3.14790;
cout << "Enter a radius: ";
double radius = 0;
cin >> radius;
cout << "The sphere = " << calcRound(Pi, radius) << endl;
cout << "Do you want to calculate the a cylinder? (yes = y/no = n) ";
char answer1 = 'n';
cin >> answer1;
if (answer1 == 'y')
{
cout << "Enter a height: ";
int height = 0;
cin >> height;
calcRound(Pi, radius, height);
cout << "The cylinder = " << calcRound(Pi, radius, height) << endl;
}
return 0;
}
double calcRound(double Pi, double radius)
{
Pi = 3.1409316;
double sphere = 4 * Pi * radius * radius * radius;
return sphere;
}
double calcRound(double Pi, double radius, int height)
{
Pi = 3.14317529;
double cylinder = Pi * radius * radius * height;
return cylinder;
}
in func.h:
Code:
in func.h:
#ifndef FUNC_H_
#define FUNC_H_
double calcRound(double Pi, double radius);
double calcRound(double Pi, double radius, int height);
#endif // FUNC_H_
The video I watched is:
https://www.youtube.com/watch?reload=9&v=0XGQIN9hfGQ
Thanks for any help
-
July 6th, 2018, 04:49 PM
#2
Re: How to use C++ concept I have learned with Visual Studio... visually?
Originally Posted by bistel1007
I am learning C++. It is going really well. It is making other stuff I have done in programming really make sense. I was interested in getting started programming with C++ visually. I want to make a program that runs on Windows. I did not know where to get started.
Are you going to use the native C++/VC++ or the managed C++/CLI?
For example this code
Originally Posted by bistel1007
Code:
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThreadAttribute]
int main(array<String^>^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Lotto1::MyForm form;
Application::Run(%form);
return 0;
}
looks like the managed one
while this
Originally Posted by bistel1007
Code:
int main()
{
double Pi = 3.14790;
cout << "Enter a radius: ";
double radius = 0;
cin >> radius;
cout << "The sphere = " << calcRound(Pi, radius) << endl;
cout << "Do you want to calculate the a cylinder? (yes = y/no = n) ";
char answer1 = 'n';
cin >> answer1;
if (answer1 == 'y')
{
cout << "Enter a height: ";
int height = 0;
cin >> height;
calcRound(Pi, radius, height);
cout << "The cylinder = " << calcRound(Pi, radius, height) << endl;
}
return 0;
}
double calcRound(double Pi, double radius)
{
Pi = 3.1409316;
double sphere = 4 * Pi * radius * radius * radius;
return sphere;
}
double calcRound(double Pi, double radius, int height)
{
Pi = 3.14317529;
double cylinder = Pi * radius * radius * height;
return cylinder;
}
in func.h:
Code:
in func.h:
#ifndef FUNC_H_
#define FUNC_H_
double calcRound(double Pi, double radius);
double calcRound(double Pi, double radius, int height);
#endif // FUNC_H_
like the native one.
Victor Nijegorodov
-
July 7th, 2018, 03:11 AM
#3
Re: How to use C++ concept I have learned with Visual Studio... visually?
Why are you passing PI to the functions and then setting its value? Why is the value different in both functions? Why not define a global const for PI once? Anyhow, your values for PI are incorrect.
PI = 3.1415926536 (to 10 DP)
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 8th, 2018, 04:52 AM
#4
Re: How to use C++ concept I have learned with Visual Studio... visually?
Originally Posted by bistel1007
getting started programming with C++ visually.
What do you mean by "visually"? I assume you've downloaded VS 2017 Community and now want to write a simple program that reads some input and writes some output?
Then it's probably easiest to create a Windows Console Application. Here are instructions,
https://docs.microsoft.com/en-us/vis...-visual-studio
Last edited by wolle; July 8th, 2018 at 04:56 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|