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
How to learn real c progrqming ?
What do you mean 'real'?
Anonymous
i mean not basic things. real world things like file managers or word processing
Prometheus
i mean not basic things. real world things like file managers or word processing
Like you want to write a file manager or word processor?
Prometheus
I’d look into something like QT for it
mine.rbitcoin
Bro this group is for learning c++ or to solve problems in our program.
Anonymous
Anonymous
i thought friend is a function only .idk about friend class ,😶
レッギ
i thought friend is a function only .idk about friend class ,😶
You can access other private member class since you make it be 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
Anonymous
I have a question
Anonymous
How can i rotate pgm image with c
klimi
How can i rotate pgm image with c
i guess you just rotate it and save to the disk
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
can we use setData function to give input to object of both class??
Just do x=a.x inside setData I guess Or the other way round, cin >> x a.x = x Since you're calling it from B's object, x will refer to B's x by default
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
in how many ways can write a "Hello World" program in C++
in as many ways as a hello world can be resembled
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
This is the output I have to execute 1st row by integer division and 2nd row/remainder by modulus
Show an example of what kind of divisions you're trying to perform
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
Can someone please give tips for freshers ? 👀
Anonymous
You can stop using modulus altogether. Quarters = 0.51/0.25 = 2 Remainder = 0.51 - (no. of quarters * cost per quarter) = 0.51 - 2*0.25 = 0.01
You're doing it all with arithmetics (/-*) But Where's the use of % here? Actually it was a requirement of my assignment
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
?
Anonymous
can anyone help me to understand the friend function 😢😢
coal
can anyone help me to understand the friend function 😢😢
do you know what private: and protected: does
coal
a friend function allows you to access anything that was declared within private or protected from a foreign class
\Device\NUL
in how many ways can write a "Hello World" program in C++
Using standard library (iostream or cstdio) or using kernel syscall (windows.h, unistd.h)
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
Engineer
If u can debug it that’s would be amazing I have been trying to fix the logical error for days
Best way to debug this is to make a copy of this program and hard copy the values you want to enter. Then you should be able to get a better understanding of what is going wrong
David
And I have used calculator to calculate it
Engineer
And I have used calculator to calculate it
Can you try with 1 as the input for all inputs?
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?
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
Not one Read it well
klimi
I divided by 12.0
in the code you have provided you are dividing it by 1
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?
\Device\NUL
For char data type?
printf("%c", '%') printf("%%")