Ilya
void main() { int n,sum=0; int a[5],i,min=a[0],max=a[0]; printf("Enter the array values: "); for(i=0; i<n; i++) { scanf("%d",&a[i]); sum=sum+a[i]; if (0 == i) { max = a[0]; min = a[0]; } if(min>a[i]) { min=a[i]; } if(max<a[i]) { max=a[i]; } } }
neovstan
And what’s the reason they should initialize by a[0]???
Bilal
#include <iostream> #include <concepts> #include <type_traits> std::integral auto add(std::integral auto a, std:: integral auto b){ return a + b; } int main(){ add(3,5); return 0; std::cout << "Done" << std::endl; }
Bilal
issue : integreal in namespace 'std' does not name a type ....!
klimi
issue : integreal in namespace 'std' does not name a type ....!
no errors on my machine, what standard are you using? + compiler?
klimi
gcc version 12.2.0 (GCC) with --std=c++20
Bilal
gcc 11.3.0
Raditya
can we make cartesian coordinates in c++?
ً
Hi guys I really need help on something for my project can someone help me
Reitero
good I want to make a program in c of logical and rational operators can guide me thanks
Anonymous
How to delete a single record in an object array?
Sid
Hello what will be the time complexity of this code
Sid
void primeFactor(int &n){ for(int i = 2; i<n; i++){ if(isPrime(i)){ int x = i; while(n%x==0){ cout<<i<<" "; x=x*i; } } } }
Sid
I think bigO(nlogn)
Sid
Just wanna confirm
No Name
And just write O(nlogn)
Sid
Had written for understand purpose
No Name
i could be 2 minimum, the result is the max number of operations
Sid
And just write O(nlogn)
O(n) for outermost loop and O(log) for inner! I'm I right
No Name
log*n for the inner, yes
klimi
How to delete a single record in an object array?
you just delete it? if you don't want the gab or want to keep the array sorted you will need to move all the after objects by -1
klimi
can we make cartesian coordinates in c++?
Dunno what exactly you are asking but since c++ is turing complete, then probably yes c:
🤗
Guys hi there
🤗
#include <stdio.h> int main() int x = 1, product = 0; while ( x <= 10 ); product *= x; =++x
🤗
At last one which one is error?
Pavel
At last one which one is error?
You don't have curly braces =++x what is this even? You have semicolon after your while loop making it do nothing.
Ilya
#include <stdio.h> int main() int x = 1, product = 0; while ( x <= 10 ); product *= x; =++x
#include <stdio.h> int main() { int x = 1, product = 1; while ( x <= 10 ) { product *= x; ++x; } return 0; }
Pavel
Yes my question is how to delete it😌?
You have C-style array or std::vector? Or std::array?
klimi
Yes my question is how to delete it😌?
well that depends on your interpretation? does the object have constructor? how do you represent empty cell in your array?
Pavel
Std::array
If you want to shift the empty element to the right (you haven't specified what you want so I assume this). If you want to do that manually, you can iterate from the deleted element position + 1 to last position, and (move)assign the element to the previous element. Depending on the types of the element you would want to move them (majority of types), copy them (basic types, or if you don't care about efficiency), or you can use memcpy (trivially copyable types, only if you need to do that as fast as you can). Or you can use this, it will do this all for you (should be something like this) std::move(std::begin(arr) + (pos + 1), std::end(arr), std::begin(arr) + pos); Or you can use iterator to your element instead of std::begin(arr) + pos https://en.cppreference.com/w/cpp/algorithm/move
Anonymous
well that depends on your interpretation? does the object have constructor? how do you represent empty cell in your array?
Class Person { Public: String Name,EmailAdderess,Address; Int Age ; }; I created an object for that class called Person Ppl [5]; It has Subclasses : Class Student:public Person { Public: String Grade; Int Class; void addStudentRecord(); void DisplayStudentRecords(); Void DeleteStudentRecord(); }; Also created an object for it called Student S[5]; I have no problem with the first 2 functions(add and Display) At first i just did String name; Cout<<"enter name"; Cin>>name; If (name==Ppl[i].Name){ Name=" ";(did this for all atributues)}; Which worked just fine but the problem with this way was that, i can not assing a string (" ")to an integer Age. So my question is: is there a way to permanently delete a record Or how to use the delete Function/clear function I hope you find it easy to understand my question
Pavel
Class Person { Public: String Name,EmailAdderess,Address; Int Age ; }; I created an object for that class called Person Ppl [5]; It has Subclasses : Class Student:public Person { Public: String Grade; Int Class; void addStudentRecord(); void DisplayStudentRecords(); Void DeleteStudentRecord(); }; Also created an object for it called Student S[5]; I have no problem with the first 2 functions(add and Display) At first i just did String name; Cout<<"enter name"; Cin>>name; If (name==Ppl[i].Name){ Name=" ";(did this for all atributues)}; Which worked just fine but the problem with this way was that, i can not assing a string (" ")to an integer Age. So my question is: is there a way to permanently delete a record Or how to use the delete Function/clear function I hope you find it easy to understand my question
So let's start from the beginning: > I created an object for that class called Person Ppl [5]; You've created array of five objects (by the way, this is c-style array, not std::array). Second, your DeleteStudentRecord is part of the class, that means it doesn't have any information about the array and can't change anything related to the array. You can clear the data, but the item in the array will remain. c-style arrays and std::arrays are fixed size, meaning you can't reduce or increase the size of them during runtime. That means, if you have 5 elements of the array, and want to delete an element, you can: - Add some bool to the element to denote that the element is in "deleted"/"empty" state, ignore the elements with that state. - Or shift the element you want to delete to the end (all the elements after it one step to the left), and store the dynamic size that will show how many "alive" elements you have. Or if you don't care about the order, just move the last element to the deleted position and decrease your size variable by one. If you want to have an array that can be resized, use std::vector
Anupam2.7
Can we create more than one parameterized constructor in c++?
Pavel
Can we create more than one parameterized constructor in c++?
If you mean constructors that take arguments, you can just declare them one after another. Or you have a problem doing that?
Anupam2.7
If you mean constructors that take arguments, you can just declare them one after another. Or you have a problem doing that?
If i create two constructor within same class, first one takes two arguments and second one takes three arguments. Then i create a object of that class and pass two arguments then how will it works?
Anupam2.7
Constructor with 2 parameters will be used.
and what happens to the constructor with three arguments?
Azat
It automatically selects the one with given number of parameters and calls only it
Pavel
If i create two constructor within same class, first one takes two arguments and second one takes three arguments. Then i create a object of that class and pass two arguments then how will it works?
It works similarly to function overloading rules, the compiler will find the most appropriate constructor for the arguments you passed. There are different rules for resolution, but unless you have implicit constructors with one argument, it should call the constructors you expect or fail at compile time https://en.cppreference.com/w/cpp/language/overload_resolution
Руслан
Hello, i have small problem bool zero = 0; int a, b, x = 0; int five = 5; // Инициализация printf("\na, b: "); scanf_s("%d",&a); scanf_s("%d",&b); //=============================== C ================================== if (a = b) { x += five; } if (a < b) { if (a == 0) { zero++; } else { //b /= a; //b += five; //x += b; x = b / a + 5; } } else { if (b == 0) { zero++; } else { //a *= a; //a -= b; //a /= b; //x += a; x = (a * a - b) / b; } } if (zero) { printf("Division by zero"); } else { printf("%d", x); } return 0;
Руслан
If i enter a = 1, b = 1 => x = 0, if a = 5, b = 5 => x = 4. Why?
Anonymous
Hello is there any website that explains codes and shows what they do, also analysis?
Руслан
sorry
Руслан
But i can send screen
Руслан
I edit if (a == b) { x = 5; } And receive x = 4
Anonymous
I edit if (a == b) { x = 5; } And receive x = 4
This line will also get executed: x = (a*a-b)/b
Руслан
Anonymous
It`s else for if ( a < b)
When a==b, the else for if(a<b) will get executed
Руслан
Make if else if else?
Руслан
I wrote under the logic of assembly language, and completely forgot about the logic of C
นะวู
Can anyone helps me with this problem? Create a program where given a string S which may only contain lowercase letters (a-z),numbers, spaces, and symbols #$ % & * ’ ” - the program will remove all characters which are not part of the alphabet (which are numbers, spaces, and symbols). Format Input The first line contains a single number T, the number of testcases. Each testcase consists of two lines. The first line of each testcase contains N, which is the length of string S. The second line of each testcase contains the string S itself. Format Output The output consists of T lines where each line contains “Case #X: ” (without quotes) where X is the testcase number (starting from 1) and then followed by string S with all numbers, spaces, and symbols removed. Constraints • 1 ≤ T ≤ 100 • 1 ≤ N ≤ 100 • S may only contain a-z, numbers, spaces, and symbols #$ % & * ’ ” - •S contains at least one alphabet Sample Input (standard input) 3 18 november 22nd 1919 36 n$e ve#- rg%&on$ n#ag i've y*o u"up- 28 i don't wanna be you anymore Sample Output (standard output) Case #1: novembernd Case #2: nevergonnagiveyouup Case #3: idontwannabeyouanymore
Anonymous
Guys, instruct me pls In b = 6.6/a + (2*a + (3*c) / a*d) / (2/n); Which operation will be performed first: a) 6.6/a; b) 2*a; c) 3*c; d) 2/n;
Anonymous
c
Anonymous
c
why ? why not a ?
Anonymous
becoseBecause it came between two ()
Pavel
becoseBecause it came between two ()
I'm not sure it matters here
Pavel
I'm also not sure if the order of these 4 operations is defined 🤔
_VVV_
https://learn.microsoft.com/ru-ru/windows/win32/psapi/enumerating-all-processes all the processes that I found in this way turned out to be user (I compared their sid and user) how to find all the others?
Anonymous
i have proplem with this code ,when i run it with devc++ it work normaly but it`s not working with visual studio
Anonymous
#include <stdio.h> int main() { int number; printf("plase enter a number"); scanf("%d",&number); if(number>0) { printf("pozitif"); } else { if (number == 0) { printf("number is eaqul 0") ; } else { printf("the number is negatif"); } } }
Anonymous
What is function call overhead and inline function in lame man's language please
Anonymous
i`m using c language
The_Sea
Hi I want to help about program for c++ please 🥺