coal
a friend function can access private and protected members of the class that defines it as a friend
Anonymous
How to learn real c progrqming ?
Anonymous
i mean not basic things. real world things like file managers or word processing
Prometheus
Prometheus
I’d look into something like QT for it
Anonymous
mine.rbitcoin
Bro this group is for learning c++ or to solve problems in our program.
Prometheus
Anonymous
Anonymous
i thought friend is a function only .idk about friend class ,😶
RHD
Could you please recommend a beginner friendly testing library for C++? (In a sense of simple to setup and simple to use) I've checked out google test, but I'm kind of overwhelmed by its complexity and I don't think I need all the features (I don't even know what they are). I just want to develop a habit to test everything I write. Once I get used to it, I will move on to a better one. Thank you.
shriman_deepak
Hey anyone know what's wrong with code chef ?
shriman_deepak
It always giving me sigcont error
mayway
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int n;
cin>>n;
int ans=0;
int i=0;
while(n!=0){
int bit = n & 1;
ans= (bit * pow(10, i) ) + ans;
n = n >> 1;
i++;
}
cout<<ans<<endl;
}
mayway
plz check my code
mayway
Hima
Anonymous
I have a question
Anonymous
How can i rotate pgm image with c
Anonymous
#include <iostream>
using namespace std;
class B;
class A
{
int x = 4;
friend class B; // friend class
};
class B
{
public:
void display(A &a)
{
cout << " the value of class A is " << a.x<<endl;
}
void setData(A &a);
};
void B::setData(A &a)
{
cout << " enter the value of B : ";
cin >> a.x;
}
int main()
{
A a;
B b;
b.display(a);
b.setData(a);
cout<<"+++++++++++++++++++"<<endl;
b.display(a);
return 0;
}
Anonymous
can we use setData function to give input to object of both class??
Anonymous
using a class's object ( like B ) ?? is this possible ??
Anonymous
Anyone good at C?
Your help will be appreciated
A.M UMAR
Drop your problem and lets see
Anonymous
Sales EXCLUDING tax
Coin Qty Balance
-------- --- ---------
323.5100
Toonies 161 1.5100
Loonies 1 0.5100
Quarters 2 0.0100
Dimes 0 0.0100
Nickels 0 0.0100
Pennies 1 0.0000
Anonymous
This is the output
I have to execute 1st row by integer division and 2nd row/remainder by modulus
Anonymous
My problem is with the remainders as I can not go on with double here...how am i supposed to have outputs with decimal point numbers
Anonymous
I wanted to show my code..but it says picture sharing is restricted
Anonymous
in how many ways can write a "Hello World" program in C++
coal
coal
for example, printing hello world to the console can be done via cout or cerr or clog or printf
coal
creating a hello world string can be done with std::string, with a char*, with a literal byte array (without using "" but rather numbers), etc...
coal
you can also print a hello world from a microcontroller if it has a display
coal
its unquantifiable
Anonymous
Anonymous
Show an example of what kind of divisions you're trying to perform
For first row it's integer division with casting, as the dollars in balance row are in decimal point.. I casted it to -
// Toonies = 2 dollars
int toonies;
double dollars = 323.5100;
toonies = (int)dollars / 2 = 161;
// casting & integer division;
double remainder1;
remainder1 = dollars % 2 + .51;
= 1.5100;
And with this data I can print out first line of Toonies.
But the problem raised from quarters...as we know a quarter means 25 cents or .25 dollars.
But I can not assign a decimal point value like .25 after modulus.
So how am i supposed to write this code for remainders?
Anonymous
Anonymous
Can someone please give tips for freshers ? 👀
Anonymous
M
Ok
Anonymous
#include <stdio.h>
int main()
{
int choice;
printf("enter a any letter from A to E");
scanf("%s",& choice);
switch(choice){
case A:
printf("first class honours");
break;
case B:
printf("second upper honours");
break;
case C:
printf("second lower honours");
break;
case D:
printf("pass");
break;
case E:
printf("fail");
break;
}
return 0;
}
Anonymous
What is wrong with this codes
Sachin
Function with same name and same no of parameters and same type of parameters just differ in return type In same scope is not acceptable in CPP ?
Sachin
?
innocent
Anonymous
can anyone help me to understand the friend function 😢😢
coal
coal
a friend function allows you to access anything that was declared within private or protected from a foreign class
Anonymous
David
/*loan.c
 
computes monthly and total payment of a loan based on interest rate and number of years.
4  
5 */
6  
7 #include <stdio.h>
8 #include <math.h>
9  
10 void computeLoan(double amount, double interest, int years){
11  
12 // declarations
13 double monthlyPayment, totalPayment, monthlyInterest;
14  
15 // compute monthly and total payment
16 monthlyInterest = interest / 12.0;
17 double numeratorOfMonthlyPaymentFormular = (amount * monthlyInterest) / 1;
18 double denumenatorOfMonthlyPaymemtFormular = 1 - (1 / (pow((1 + monthlyInterest),(years * 12))));
19 monthlyPayment = numeratorOfMonthlyPaymentFormular / denumenatorOfMonthlyPaymemtFormular;
20  
21 totalPayment = monthlyPayment * years * 12;
22  
23 // display the monthly and total payment
24 printf("---------------------------------");
25 printf("\nThe monthly payment is %.2lf ", monthlyPayment);
26 printf("\nThe total payment is %.2lf", totalPayment);
27 printf("\n---------------------------------");
28 }
29  
30 int main(){
31 //declarations
32 double amount, interest;
33 int years;
34 char percent_sign = '%';
35  
36 // prompt user to enter interest rate
37 printf("Enter annual interest rate in %c, e.g. 5.75: ", percent_sign);
38 scanf("%lf", &interest);
39  
40 // prompt user to enter loan amount
41 printf("Enter loan amount, e.g. 12000.95: ");
42 scanf("%lf", &amount);
43  
44 // prompt user to enter number of years
45 printf("Enter number of years as an integer, e.g. 5: ");
46 scanf("%d", &years);
47  
48 // call the function computeLoan()
49 computeLoan(amount, interest, years);
50  
51 return 0;
52 }
53  
David
There is a logical error in the code
David
When user inputs 5.75 as interest
And 250000 as loan amount
And then 15 as the number of year
David
It outputs $2076.03 as the monthly payment
David
And $373684.54 as the total payment
David
But the program is giving a different value
David
If u can debug it that’s would be amazing
I have been trying to fix the logical error for days
David
David
And I have used calculator to calculate it
David
Engineer
Ok
Then try 10 for all inputs.
Engineer
You should be able to see what is going wrong
Engineer
Ok
Are you using a computer or an android smartphone as your development device?
David
RHD
/*loan.c
 
computes monthly and total payment of a loan based on interest rate and number of years.
4  
5 */
6  
7 #include <stdio.h>
8 #include <math.h>
9  
10 void computeLoan(double amount, double interest, int years){
11  
12 // declarations
13 double monthlyPayment, totalPayment, monthlyInterest;
14  
15 // compute monthly and total payment
16 monthlyInterest = interest / 12.0;
17 double numeratorOfMonthlyPaymentFormular = (amount * monthlyInterest) / 1;
18 double denumenatorOfMonthlyPaymemtFormular = 1 - (1 / (pow((1 + monthlyInterest),(years * 12))));
19 monthlyPayment = numeratorOfMonthlyPaymentFormular / denumenatorOfMonthlyPaymemtFormular;
20  
21 totalPayment = monthlyPayment * years * 12;
22  
23 // display the monthly and total payment
24 printf("---------------------------------");
25 printf("\nThe monthly payment is %.2lf ", monthlyPayment);
26 printf("\nThe total payment is %.2lf", totalPayment);
27 printf("\n---------------------------------");
28 }
29  
30 int main(){
31 //declarations
32 double amount, interest;
33 int years;
34 char percent_sign = '%';
35  
36 // prompt user to enter interest rate
37 printf("Enter annual interest rate in %c, e.g. 5.75: ", percent_sign);
38 scanf("%lf", &interest);
39  
40 // prompt user to enter loan amount
41 printf("Enter loan amount, e.g. 12000.95: ");
42 scanf("%lf", &amount);
43  
44 // prompt user to enter number of years
45 printf("Enter number of years as an integer, e.g. 5: ");
46 scanf("%d", &years);
47  
48 // call the function computeLoan()
49 computeLoan(amount, interest, years);
50  
51 return 0;
52 }
53  
I haven't read all of it, but, line 17 looks weird. What's the purpose of dividing something by 1?
David
David
Not one
Read it well
klimi
David
RHD
/*loan.c
 
computes monthly and total payment of a loan based on interest rate and number of years.
4  
5 */
6  
7 #include <stdio.h>
8 #include <math.h>
9  
10 void computeLoan(double amount, double interest, int years){
11  
12 // declarations
13 double monthlyPayment, totalPayment, monthlyInterest;
14  
15 // compute monthly and total payment
16 monthlyInterest = interest / 12.0;
17 double numeratorOfMonthlyPaymentFormular = (amount * monthlyInterest) / 1;
18 double denumenatorOfMonthlyPaymemtFormular = 1 - (1 / (pow((1 + monthlyInterest),(years * 12))));
19 monthlyPayment = numeratorOfMonthlyPaymentFormular / denumenatorOfMonthlyPaymemtFormular;
20  
21 totalPayment = monthlyPayment * years * 12;
22  
23 // display the monthly and total payment
24 printf("---------------------------------");
25 printf("\nThe monthly payment is %.2lf ", monthlyPayment);
26 printf("\nThe total payment is %.2lf", totalPayment);
27 printf("\n---------------------------------");
28 }
29  
30 int main(){
31 //declarations
32 double amount, interest;
33 int years;
34 char percent_sign = '%';
35  
36 // prompt user to enter interest rate
37 printf("Enter annual interest rate in %c, e.g. 5.75: ", percent_sign);
38 scanf("%lf", &interest);
39  
40 // prompt user to enter loan amount
41 printf("Enter loan amount, e.g. 12000.95: ");
42 scanf("%lf", &amount);
43  
44 // prompt user to enter number of years
45 printf("Enter number of years as an integer, e.g. 5: ");
46 scanf("%d", &years);
47  
48 // call the function computeLoan()
49 computeLoan(amount, interest, years);
50  
51 return 0;
52 }
53  
I think it's the percentage, maybe... from the example user inputs "plain" percentage (whatever it's called), but in the code I don't see any conversion from, say 5% to 0.05. If it's multiplied somewhere with an amount, you don't get 5 percent of that amount, but 5x
\Device\NUL
/*loan.c
 
computes monthly and total payment of a loan based on interest rate and number of years.
4  
5 */
6  
7 #include <stdio.h>
8 #include <math.h>
9  
10 void computeLoan(double amount, double interest, int years){
11  
12 // declarations
13 double monthlyPayment, totalPayment, monthlyInterest;
14  
15 // compute monthly and total payment
16 monthlyInterest = interest / 12.0;
17 double numeratorOfMonthlyPaymentFormular = (amount * monthlyInterest) / 1;
18 double denumenatorOfMonthlyPaymemtFormular = 1 - (1 / (pow((1 + monthlyInterest),(years * 12))));
19 monthlyPayment = numeratorOfMonthlyPaymentFormular / denumenatorOfMonthlyPaymemtFormular;
20  
21 totalPayment = monthlyPayment * years * 12;
22  
23 // display the monthly and total payment
24 printf("---------------------------------");
25 printf("\nThe monthly payment is %.2lf ", monthlyPayment);
26 printf("\nThe total payment is %.2lf", totalPayment);
27 printf("\n---------------------------------");
28 }
29  
30 int main(){
31 //declarations
32 double amount, interest;
33 int years;
34 char percent_sign = '%';
35  
36 // prompt user to enter interest rate
37 printf("Enter annual interest rate in %c, e.g. 5.75: ", percent_sign);
38 scanf("%lf", &interest);
39  
40 // prompt user to enter loan amount
41 printf("Enter loan amount, e.g. 12000.95: ");
42 scanf("%lf", &amount);
43  
44 // prompt user to enter number of years
45 printf("Enter number of years as an integer, e.g. 5: ");
46 scanf("%d", &years);
47  
48 // call the function computeLoan()
49 computeLoan(amount, interest, years);
50  
51 return 0;
52 }
53  
Please use %% instead of "%c", '%' on the printf
David
For char data type?