15,910,981 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 12959299 (Top 23 by date)
Member 12959299
8-Oct-20 0:52am
View
This question has been answered here - https://stackoverflow.com/a/64057717/7444874
Member 12959299
8-Oct-20 0:51am
View
This question has been answered here - https://stackoverflow.com/a/64057717/7444874
Member 12959299
5-Mar-17 0:29am
View
Thank you so much for writing in detail.
Member 12959299
2-Feb-17 11:55am
View
Deleted
OK now, the complete exercise is:-
Create a class called Triangle that stores the length of the base and height of a right triangle in two private instance variables. Include a constructor that sets these values. Define two functions. The first is hypot( ), which returns the length of the hypotenuse. The second is area( ),which returns the area of the triangle.
The program is :-
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
class triangle
{
private:
double length,height,ar,hyp;
public:
triangle(double l, double h);
double hypot();
double area();
};
triangle::triangle(double l, double h)
{
length=l;
height=h;
}
double triangle::hypot()
{
hyp=sqrt(pow(length,2)+pow(height,2));
return hyp;
}
double triangle::area()
{
ar=(length*height)/2;
return ar;
}
main()
{
double l,h;
clrscr();
cout<<"enter length of the base of the right angled triangle: ";
cin>>l;
cout<<"\nenter height the right angled triangle: ";
cin>>h;
triangle o(l,h);
cout<<o.hypot();
cout<<o.area();
getch();
}
/*Everything is well when I call either of the functions cout<<o.hypot(); or cout<<o.area(); once everytime I run the program, but when I call the functions together, then it gives me the wrong answer.
eg. if I enter the length and height of the triangle as 4 and 3 respectively, and call the function cout<<o.hypot(); it shows hypotenuse as 5 or if I call the function cout<<o.area(); it shows area as 6, both of which are correct, but when I call both the functions together, it shows just one answer 56 which neither the hypotenuse nor the area. How to correct it ?*/
Member 12959299
2-Feb-17 9:26am
View
Yes, confusing for a beginner
Member 12959299
2-Feb-17 9:24am
View
Deleted
What I did was cout<<o.area in main(). I think I got the point. Thanks all of you.
Member 12959299
2-Feb-17 9:20am
View
Thanks Mr. Pallini for replying me for the second time.
Member 12959299
2-Feb-17 9:19am
View
Thanks Mr. Pfeffer
Member 12959299
2-Feb-17 9:18am
View
Thanks Mr. Holguin
Member 12959299
1-Feb-17 6:28am
View
thanks for your help guys. sorted.
Member 12959299
1-Feb-17 6:26am
View
It works using strcpy. The complete correct program is:-
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
class message
{
private:
char sender[10],recipient[10];
int time;
public:
message(char s[10],char r[10],int t)
{
strcpy(sender,s);
strcpy(recipient,r);
time=t;
}
void print();
};
void message::print()
{
cout<<"\nthe sender is: "<<sender;
cout<<"\nhe recipient is : "<<recipient;
cout<<"\ncurrent time is : "<<time;
}
main()
{
char s[10], r[10];
int t;
clrscr();
cout<<"\nenter senders name :";
cin>>s;
cout<<"\nenter recipient name :";
cin>>r;
cout<<"\nenter current time :";
cin>>t;
message c(s,r,t);
c.print();
getch();
}
Member 12959299
1-Feb-17 6:24am
View
Deleted
It works strcpy.
The correct working program is:-
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
class message
{
private:
char sender[10],recipient[10];
int time;
public:
message(char s[10],char r[10],int t)
{
strcpy(sender,s);
strcpy(recipient,r);
time=t;
}
void print();
};
void message::print()
{
cout<<"\nthe sender is: "<<sender;
cout<<"\nhe recipient is : "<<recipient;
cout<<"\ncurrent time is : "<<time;
}
main()
{
char s[10], r[10];
int t;
clrscr();
cout<<"\nenter senders name :";
cin>>s;
cout<<"\nenter recipient name :";
cin>>r;
cout<<"\nenter current time :";
cin>>t;
message c(s,r,t);
c.print();
getch();
}
Member 12959299
30-Jan-17 23:36pm
View
string works fine on other compiler online. Turbo c is dinosaur but told to work on turbo c by my senior. Thank you sir.
Member 12959299
30-Jan-17 23:36pm
View
string works fine on other compiler online. Turbo c is dinosaur but told to work on turbo c by my senior. Thank you sir.
Member 12959299
30-Jan-17 23:34pm
View
Deleted
string works fine on other compiler online. Turbo c is dinosaur but told to work on turbo c by my senior. Thank you sir.
Member 12959299
30-Jan-17 13:02pm
View
thanks for your suggestion, Mr MacCutchan. I am using turbo c++ compiler, and as far as I know, it does not accept strings. When I tried to use string as suggested by CPallini below it showed errors which you can see in my reply to CPallini's comments. So, I do not know how to sort this thing out.
Member 12959299
30-Jan-17 13:02pm
View
thanks for your suggestion, Mr MacCutchan. I am using turbo c++ compiler, and as far as I know, it does not accept strings. When I tried to use string as suggested by CPallini below it showed errors which you can see in my reply to CPallini's comments. So, I do not know how to sort this thing out.
Member 12959299
30-Jan-17 12:03pm
View
When I run the above program, it shows the following errors :-
#include <string>
#include <iostream>
using namespace std;
class message
{
string sender;//type name expected, declaration missing
string recipient;/*type name expected , multiple declaration for string declaration for string, declaration missing */
int time;
public:
message(string s, string r, int t): sender(s), recipient(r), time(t){}/
* ) expected */
void print();
};
void message::print()// 'message ::print is not a member of 'message'
{
cout << "the sender is " << sender << endl;
cout << "the recipent is " << recipient << endl;
cout << "the time is " << time << endl;
}
int main()
{
string s,r;
int t;
cout<<"enter senders name :";
cin>>s; // undefined symbol 's'
cout<<"enter recipient name :";
cin>>r; //undefined symbol 'r'
cout<<"enter time :";
cin>>t;
message c(s,r,t); // ) expected
c.print(); //'print' is not a member of 'message', function sh. re. a va.
} //c is assinged a value which is never used.
please note that I am using a tsuppourbo c compiler and as far as I know, it does not support string, but it supports char arrays, so could you please tell me how to use it that way. I will be obliged.
Member 12959299
30-Jan-17 8:21am
View
can you please tell me how to use string and char arrays for expressions like
"sender=s". I would be grateful.
Member 12959299
21-Jan-17 4:24am
View
thanks for your suggestion.
Member 12959299
21-Jan-17 4:21am
View
silly mistake. yes, its working. Thanks for your precious time.
Member 12959299
20-Jan-17 8:05am
View
thank u sir/mam
Member 12959299
20-Jan-17 8:04am
View
thank u sir/mam
Show More