[VIEWED 8364
TIMES]
|
SAVE! for ease of future access.
|
|
|
ujl
Please log in to subscribe to ujl's postings.
Posted on 09-23-14 2:28
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to khoikkhoik's postings.
Posted on 09-23-14 3:13
PM [Snapshot: 47]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
http://www.aboutcodes.com/2013/02/c-program-to-find-area-of-circle.html
|
|
|
alece
Please log in to subscribe to alece's postings.
Posted on 09-23-14 7:15
PM [Snapshot: 154]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to ujl's postings.
Posted on 09-23-14 8:57
PM [Snapshot: 219]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to sojoketo's postings.
Posted on 09-23-14 9:04
PM [Snapshot: 227]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to alece's postings.
Posted on 09-24-14 9:52
AM [Snapshot: 337]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to alece's postings.
Posted on 09-24-14 9:54
AM [Snapshot: 337]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to ujl's postings.
Posted on 09-24-14 1:54
PM [Snapshot: 399]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to sajhamitra's postings.
Posted on 09-24-14 3:24
PM [Snapshot: 433]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to alece's postings.
Posted on 09-24-14 3:43
PM [Snapshot: 443]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to sojoketo's postings.
Posted on 09-24-14 7:31
PM [Snapshot: 492]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to sajhamitra's postings.
Posted on 09-24-14 8:43
PM [Snapshot: 526]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to sojoketo's postings.
Posted on 09-24-14 11:06
PM [Snapshot: 558]
Reply
[Subscribe]
|
Login in to Rate this Post:
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
Please log in to subscribe to aaitey's postings.
Posted on 09-25-14 6:44
AM [Snapshot: 609]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
चट्ट लाएर ग्याँस स्टेसनमा घण्टा हान्ने, क्यासमा काम गर्ने, फुडस्ट्याम्प खाने, सरकारी ईन्सुरेन्स लिने, सुटकेशमा डलर ढुसी लागुन्जेल जम्मा गर्न छोडेर, किन c++ हो कि v++ तिर लाग्न थाले केटकेटीहरु :)
|
|
|
Rufuz
Please log in to subscribe to Rufuz's postings.
Posted on 09-28-14 10:10
AM [Snapshot: 775]
Reply
[Subscribe]
|
Login in to Rate this Post:
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.
|
|
|