Nuruberry
Hy
Nuruberry
ASSIGNMENT THREE (FUNCTIONS) Write a single C++ program with the following functions. 1. A function called swap that will receive two variables x and y and swaps their values such that the value of x will be placed in y and the value of y will be placed in x. 2. The second function will be called maxi, it will receive two variables and return the maximum of the two values. 3. The third function shall also be called maxi it will receive three variables and return the maximum of the three values. 4. The last function shall be called fibonacci, it will receive a variable n and displays the first n fibonacci sequence. Each number in the a fibonacci sequence is the sum of the two numbers that precede it. So, the sequence goes like this 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on. The first and the second values in a fibonacci sequence are 0 and 1. So if for instance someone inputs n as 7, your function should display 0,1,1,2,3,5,8 Hint 1 You will use your understanding of parameter passing by reference to write function swap. Hint 2: You will use your understanding of function overload to handle function 2 and function 3 called maxi NOTE The program should be able to ask the user the operation he/she wants to perform, the choice of the user will determine the function to be called at any particular time.
Nuruberry
Please somebody should help me out 🙏🙏🙏🙏🙏🙏🙏🙏🙏
Pavel
Please somebody should help me out 🙏🙏🙏🙏🙏🙏🙏🙏🙏
Have you read the rules? If yes, can you describe what kind of help you need?
Nuruberry
Have you read the rules? If yes, can you describe what kind of help you need?
This is my first year in school And I was giving that question as an assignment Need somebody to put me through
Pavel
This is my first year in school And I was giving that question as an assignment Need somebody to put me through
Ok, you didn't give any info about your prior experience or how much you have already done for this task. Do you know how to write any C++ programs? Let's look at the first task: Do you know how to write a function? Do you know how to pass an argument "by reference". If not, you can google that, and you can also google for "swap implementation C++". When you've done with that, and you are not sure about something, show us the code you have written and ask your questions. Note that if you just want someone to solve your tasks for you, you are in a wrong group. We here to learn about C/C++ and help other people learn. Doing someone's assignments/tests/exams won't help with this, on the opposite.
Nuruberry
Why did you do that
Nuruberry
I don’t no how to write on function
Pavel
I don’t no how to write on function
Did you try to search for tutorials in Google? E.g. this is for functions https://www.tutorialspoint.com/cplusplus/cpp_functions.htm This is for passing by refence with your swap example https://www.tutorialspoint.com/cplusplus/cpp_function_call_by_reference.htm
Pavel
I don’t no how to write on function
You can try to investigate about your other tasks yourself using google first, and then if you don't understand something (and can't find answer for your questions in google) ask here.
Hey
Hi is there anywhere I can learn 8066 assembly language? Been trying to input a string then print it but not sure why it's not working. So far only found videos how to input a character and print it
olli
Have browse but can’t understand
What's your question? Which part have you not understood?
Anonymous
Hey I want to link the c++ code with MySQL I need your help please
Vala
#include<iostream> #include<fstream> #include<string> using namespace std; class Car { private: string carCompany; float costCar; int numberAirbags; public: Car(){} Car(string carCompany,float costCar,int numberAirbags){ this->carCompany=carCompany; this->costCar=costCar; this->numberAirbags=numberAirbags; } string getCarCompany(){ return this->carCompany; } float getCostCar(){ return this->costCar; } int getNumberAirbags(){ return this->numberAirbags; } }; int main() { const string FILE_NAME="Cars.txt"; //Creating an array of objects of class Car Car cars[5]; cars[0]=Car("Audi",25000,4); cars[1]=Car("Ford",15000,2); cars[2]=Car("BMW",25400,2); cars[3]=Car("Honda",45604,4); cars[4]=Car("Fiat",14556,4); //write the array of objects into file. ofstream carsOfstream(FILE_NAME, ios::out); for(int i=0; i<5; ++i){ carsOfstream <<cars[i].getCarCompany() << " "<<cars[i].getCostCar()<< " "<< cars[i].getNumberAirbags()<< "\n"; } carsOfstream.close(); //read ifstream carsIfstream(FILE_NAME); if(!carsIfstream) { cerr << "Error: open file '"<<FILE_NAME<<"' for reading\n"; return 1; } string carCompany; float costCar; int numberAirbags; int counter=0; string line; //read from file while(carsIfstream>>carCompany>>costCar>>numberAirbags){ cars[counter]=Car(carCompany,costCar,numberAirbags); counter++; } carsIfstream.close(); //Search the data by carcompany from the stored file and display the result. string carcompanyTarget; int numbeOfCar=0; cout<<"Enter car company: "; getline(cin,carcompanyTarget); for(int i=0;i<5;i++) { if(cars[i].getCarCompany()==carcompanyTarget){ cout <<"Car company: "<<cars[i].getCarCompany() << ", Cost car: "<<cars[i].getCostCar()<< ", Number of airbags: "<< cars[i].getNumberAirbags()<< "\n"; numbeOfCar++; } } if(numbeOfCar==0){ cout<<"\nNot found\n\n"; } system("pause"); return 0; }
Hey I want to learn html
Prince kumar
It's a basic language bro
Anonymous
Kindly who knows how to loop in c language
Sachin
#include <bits/stdc++.h> using namespace std; int n=100000; bool sieve[n+1]; void createseive() { for(int i=0;i<=n;i++) sieve[i]=true; for(int i=2;i*i<=n;i++) { if(sieve[i]==true) for(int j=i*i;j<=n;j+=i) sieve[j]=false; } } vector<int> generateprime(int n) { vector<int> ds; for(int i=2;i*i<=n;i++) if(sieve[i]==true) ds.push_back(i); return ds; } int main() { createseive(); int t; cin>>t; while(t--) { int r,l; cin>>r>>l; vector<int> prime = generateprime(sqrt(r)); int dummy[r-l+1]; for(int i=0;i<r-l+1;i++) dummy[i]=1; for(auto pr : prime) { int firstmultiple = (l/pr)*pr; if(firstmultiple < l) firstmultiple += pr; for(int j = max(firstmultiple,pr*pr) ;j<=r ;j+=pr ) dummy[j-l]=0; } for(int i=l;i<=r;i++) { if(dummy[i-l]==1) cout<<i<<" "; } } }
Sachin
int sieve[n+1]; ^ main.cpp: In function ‘void createseive()’: main.cpp:10:6: error: ‘sieve’ was not declared in this scope sieve[i]=0; ^~~ main.cpp:14:9: error: ‘sieve’ was not declared in this scope if(sieve[i]==0) ^ main.cpp: In function ‘std::vector<int> generateprime(int)’: main.cpp:25:9: error: ‘sieve’ was not declared in this scope if(sieve[i]==0) ^~~
Sachin
error
Sachin
any one can help?
MᏫᎻᎯᎷᎷᎬᎠ
So We're around 13 months away from 23, and still don't see the cool features(pattern matching, modular std, reflections..etc) in the approved proposals list, just a small additions more like adds-on to the language. I'm recalling the scenario of C++14 which added a small but improved features on top of C++11 re-happening again Anything new?
MᏫᎻᎯᎷᎷᎬᎠ
I mean Damn, modules is still not usable in the production code for most of the compilers
James
Can someone help me with some c programing problem please do
James
Sent you
James
If anyone else is available dm I send you the doc
olli
Can someone help me with some c programing problem please do
What have you done so far? What issue have you encountered?
AS🌸
In c language Would an array of a different type affect how you accessed the array elements?
AS🌸
Thank you 🤍🤍
AS🌸
Even if we access the elements by *(array+i) It will be no different?!
Anonymous
#include<iostream.h> using namespace std; void func(int arr[]){ int j=sizeof(arr)/4; cout<<j; // should print 5 but printing 2 why????? } int main(){ int arr[]={36,7,66,87,85}; func(arr); return 0; }
Anonymous
C++ includes don’t have .h extension on them
Anonymous
only C includes have .h
Anonymous
#include<iostream.h> using namespace std; void func(int arr[]){ int j=sizeof(arr)/4; cout<<j; // should print 5 but printing 2 why????? } int main(){ int arr[]={36,7,66,87,85}; func(arr); return 0; }
You have to pass the size of an array to a function manually because a function just sees the address of the array and no other properties. In your case, you're calculating the size of an int pointer and dividing by 4, so sizeof(int) on your machine is probably 8 bytes. Pass an array of any size and it'll show 2.
Anonymous
Its so slow to complier a boost test project
Sachin
It could be because the compiler you are using doesn't support VLAs. Try changing the definition of n from int n = 100000 to const int n = 100000 or constexpr int n = 100000
// { Driver Code Starts // Initial Template for C++ #include <bits/stdc++.h> using namespace std; // } Driver Code Ends // User function Template for C++ class Solution{ public: long long primeProduct(long long l, long long r) { long long ans=1; long long s[r+1]={0}; s[0]=1; s[1]=1; for(int i=2;i*i<=r;i++)// { if(s[i]==0) for(int j=i*i;j<=r;j+=i) s[j]=1; } for(int i=l;i<=r;i++) { if(s[i]==0) ans = (ans*i)%1000000007; } return ans; } }; // { Driver Code Starts. int main(){ int t; cin>>t; while(t--){ long long L, R; cin>>L>>R; Solution ob; cout<<ob.primeProduct(L, R)<<"\n"; } return 0; } // } Driver Code Ends
Anonymous
how to make it quick
Sachin
Given two numbers L and R (inclusive) find the product of primes within this range. Print the product modulo 109+7. If there are no primes in that range you must print 1. Example 1: Input: L = 1, R = 10 Output: 210 Explaination: The prime numbers are 2, 3, 5 and 7. Example 2: Input: L = 1, R = 20 Output: 9699690 Explaination: The primes are 2, 3, 5, 7, 11, 13, 17 and 19. Your Task: You do not need to read input or print anything. Your task is to complete the function primeProduct() which takes L and R and returns the product of the primes within the range. If there are no primes in that range then return 1. Expected Time Complexity: O((R-L)*(logR)) Expected Auxiliary Space: O(sqrt(R)) Constraints: 1 ≤ L ≤ R ≤ 109 0 ≤ L - R ≤ 106
Sachin
working fine for l=10000 r=123456 ans =972859133
Ибраги́м
https://www.youtube.com/watch?v=tn69TCMdYbQ
Ибраги́м
https://www.youtube.com/watch?v=PJ-byW33-Hs
Julius
Hello madam Rose
Julius
Wow
Anonymous
Hi
Manit
Hi guys I recently started to learn C language so on which platform on Google can help me to face new problems in C language I know it's a super basic question but I really don't know
KS
You should see this! https://learncprogramiz.page.link/share-app
Où va le monde
has anyone heard about cppinstitute and them certificates?
munene
How do I write a program to compute sum of two matrices
Anonymous
How to learn DSA in easy way in c++. Any resources???
Ashish
Any one instead online classes c,c++ please contact me
SS
I need a major project! Can someone here help me with that
Alessandro
major project?
SS
major project?
For 4th year btech cse
Alessandro
which subject did you do
SS
which subject did you do
Subject as in? Are you asking about specialization?
Alessandro
yup
Alessandro
which courses you were on
Manu
I am try to coding in my vs code but it showing error ... saying .... Cannot open output file ... access denied
Manu
What should i do?
J
/get cbook
Alessandro
Ml
whats mi
SS
ML*
Anonymous
Hello