C++ guru, plz help - Sajha Mobile
SAJHA MOBILE
C++ guru, plz help
Posts 15 · Viewed 7132 · Go to Last Post
ujl
· Snapshot 0
Like · Likedby · 0
I need to create a C++ program that calculates diameter, perimeter and area of a semicircle. The formula I used is: diameter = 2r; perimeter = r ( 2 + PI ); area = PI ( r-squired ) /2;

How do I declare r? This is supposed to be in 1 nested if-then statement. I am new to c++ and I am LOST. Please help.
khoikkhoik
· Snapshot 47
Like · Liked by · 0
http://www.aboutcodes.com/2013/02/c-program-to-find-area-of-circle.html
alece
· Snapshot 154
Like · Liked by · 0
#include
using namespace std;

int main(){
const float PI = 3.1459;
float r;
double diameter, perimeter, area;
cout << "This progaram calculates diameter, perimeter and area of circle" << endl;
cout << "Please enter the radius of circle";
cin >> r;
diameter = 2 * r;
perimeter = r*(2 + PI);
area = pow(r, 2)* PI / 2;
cout << "The diameter of circle is: " << diameter << endl;
cout << "The perimeter of circle is: " << perimeter << endl;
cout << "The area of the circle is: " << area << endl;

system("pause");

}
ujl
· Snapshot 219
Like · Liked by · 0
Hi Alece, can you check where have i gone wrong?
#include
#include
using namespace std;

//Constant Declaration
const float PI = 3.14159265;


//Variable Declaration
float r;

int main()
{
string diameter;
string perimeter;
string area;
float r; //Radius of a semicircle
diameter, perimeter, area;


cout << "Input a command of either diameter, perimeter or area," << endl;
cout << "followed by a space, and float value for the radius." < cin >> r;

// ***** COMPUTATION *****
// Using nested if statements to calculate the diameter,
// perimeter, and area based on formulas provided on
// Prog1.txt

{
if ( r > 0 )

diameter = 2 * r;

perimeter = r * ( 2 + PI );

area = PI * pow(r,2) / 2;

else if ( r <= 0 )

cout << "You should have entered a positive value." << endl;
}

cout << "The diameter of a semicircle is " << diameter << endl;
cout << "The perimeter of a semicircle is " << perimeter << endl;
cout << "The area of a semicircle is " << area << endl;

return 0;
}
sojoketo
· Snapshot 227
Like · Liked by · 0
हेर बेइजात
कसले use गर्छ खै कुन्नि के जाति हो c++
ujl, साधु महाराज साधु कै जमानाको रहिछन

sorry ujl sadhu jee,

used to play around c++ once upon a time in ktm, 13 years back,
i am groovy and grails ang big data guy :P

btw ujl(ey) kina programming sikhna thaliyo ki kya ho your field ma job na payera??
just FYI, programming ain't like taking a shower ok. ROFL

Last edited: 23-Sep-14 09:10 PM
alece
· Snapshot 337
Like · Liked by · 0
I have no idea what you are doing bro...doesn't make any sense to me;
Are you looking for something like this ?
#include
#include
using namespace std;

int main(){
const float pi = 3.14159;
float r;
double diameter, perimeter, area;
string mystr;
cout << "Enter string to find" << endl;
getline(cin, mystr);
cout << "Enter radius" << endl;
cin >> r;
if (r > 0){
if (mystr == "diameter"){
diameter = 2 * r;
cout << "The diamter is :" << diameter << endl;

}
else if (mystr == "perimeter"){
perimeter = r*(2 + pi);
cout << "The perimeter is :" << perimeter << endl;

}
else if (mystr == "area"){
area = pow(r, 2)*pi / 2;
cout << "The area is :" << area << endl;
}

}
else{
cout << "idk wth to do";
}
system("pause");
}
alece
· Snapshot 337
Like · Liked by · 0
oh and include string and iostream library.... looks like sajha does not allow text between greater and less than sign to prevent XSS attack ?
ujl
· Snapshot 399
Like · Liked by · 0
Hi Alece, thank you for your help. If the user inputs r < 0, then I wanted to cout something like this : cout << You should have entered a positive value of radius. For ex:
If ( r > 0 )
}
If command is diameter, do diameter = 2 * r
else if command is perimeter do this...
else if command is area do this....
}
else if ( r < 0 )
}
cout << "You should have enter a positive value for radius." << endl;
}

return o;



sajhamitra
· Snapshot 433
Like · Liked by · 0
sojoketo, C++ is still king of all programming languages so please don't under estimate it. Microsoft, Google, Amazons are still hiring those who are proficient in C++. Infact, If you are good at C++, Algorithm & Data Structure your chance of getting hired is very high in those companies.
alece
· Snapshot 443
Like · Liked by · 0
bro..what i have written works well...u can tweak a bit to make it work the way you want...i dont know what level you are in c++ but looking at above code..it shud be easier to achieve what you want...ur code has too many flaws...post what you have done so far and let us know where you get stuck...me writing all code wont help u in longer run..
sojoketo
· Snapshot 492
Like · Liked by · 0

sajhamitra
how many c++ jobs are out in the market?
.net vs java vs c++ ??
google it, you will know.
yes, c++ is good for building up your programming skill @ the beginning
but i don't think we Nepalese are that level flexible (financially and technically)into system programming,
programming a compiler or operating system is not that fun and mind it c++ are used for that

yes ppl stil uses c++ but for programming desktop application but the world is already submerged into web.

Microsoft, Google, Amazons are still hiring those who are proficient in C++. Yes they are,
but only few. and getting hired in amazons and Google is not a piece of cake though not impossible.

hunata cobol ko pani scope xa hai kta kti ho.
sajhamitra le bhane jhai try garne ki? LOL






sajhamitra
· Snapshot 526
Like · Liked by · 0
sojoketo, Well there are tons. How do I know?? Well I used to work for one of those companies.
Check to see their SDE, SDET role's JD. Most of them requires you to have either proficient in C++ or C# or Java. It's not because you are going to work in C++ but if you are confident in C++ then you can crack any code. Not to mention they have managed C++ too. Learning new programming language syntax is not a big deal. But you should know the core.

I have seen people using C++ for middle tier applications too. So it's not just system programming.

and your quote "but i don't think we Nepalese are that level flexible (financially and technically)into system programming," is very funny dude. I have seen lot of nepalese doing system programming too. Please don't be so stereotype :).

Btw, Are you working in Big Data? I am also marching toward that career.

sojoketo
· Snapshot 558
Like · Liked by · 0
sajhamitra,
you have gone through amazon job description, not their salary variations on what programming the candidate is flexible and has experience with.
yup, c++ is a good programming language for the new bie (philosophy turned IT guy) like ujl sadhu maharaj not for a pro like sojo keto :P

true! once you are flexible with programming you can learn any programming, crack any code , but there is something call experience and experience does matter.

come on man, nepali system programmer are still seem to be  doing system programming and lasta haat ma lagyo sunne. lol

i used big data to pull the data from social networking site like facebook/ twitter to analyze it for some specific reason for which i used hortonworks though the requirement was to use hadoop.
who cares? sojoketo works the way he likes. :)


Last edited: 24-Sep-14 11:07 PM
Last edited: 24-Sep-14 11:12 PM
aaitey
· Snapshot 609
Like · Liked by · 0
चट्ट लाएर ग्याँस स्टेसनमा घण्टा हान्ने, क्यासमा काम गर्ने, फुडस्ट्याम्प खाने, सरकारी ईन्सुरेन्स लिने, सुटकेशमा डलर ढुसी लागुन्जेल जम्मा गर्न छोडेर, किन c++ हो कि v++ तिर लाग्न थाले केटकेटीहरु :)
Rufuz
· Snapshot 775
Like · Liked by · 0
Ok this is where you are doing wrong.
You are declaring diameter perimeter area as a string and calculating as a numerical value. You can not compute math on string declaration. Its is good practice to initialize the values of diameter perimeter area to 0.0.
Also read the precedence of mathematical signs in c++. Whatever is in () is carried out first so make sure you have first calculated area= (pi *pow(r,2))/2;
For logical condition:

If (r>0.0){


Do this

}

Else {
output this
}

Hope that helps.
Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 1 · Viewed 120
· Posts 1 · Viewed 111
· Posts 4 · Viewed 333
· Posts 2 · Viewed 321
· Posts 1 · Viewed 78
· Posts 1 · Viewed 108
· Posts 1 · Viewed 76
· Posts 1 · Viewed 135
· Posts 2 · Viewed 339
· Posts 12 · Viewed 1862



Your Banner Here
Travel Partners
Travel House Nepal