Chris
TYVM!!!!! I just made the adjustment you suggested and I now get the expected output for theside area of the cylinder
Chris
I made that WAY harder than it had to be
Anonymous
Maybe you right
Harsh
Yes, definately. The main purpose is a check on Data Structures and Algorithms
vinícius*
Yeah, same as #include <bits/stdc++.h> or whatever. No one is saying that's good, it's just supposed to make you write code quickly
Anonymous
Yeah, same as #include <bits/stdc++.h> or whatever. No one is saying that's good, it's just supposed to make you write code quickly
That’s is, the point is to write quickly, not to write qualitatively. I just finding something absurd in this goal. I still think competitive programmers are very smart people with good career opportunities
Chris
We just start looking into functions this week in class. I still need to gain some more expereince with applying and using these concepts. I'll take your advice and look at ways to improve the code I'm using. Starting with converting r and h in the main.
Chris
Thanks for the help I owe you one! Now maybe I'll finish the rest of my lab before 9am tomorrow morning haha
Anonymous
Yeah, I get it
Mar!o
I think competitive programmers are overrated
vinícius*
Peter Norvig said that being good at programming competitions correlates negatively with being good on the job at Google, some years ago
vinícius*
There are definitely many skills involved with competitive programming: better problem solving skills, operating under time pressure, good understanding of algorithms and data structures and so on
vinícius*
But I do think that that's something that people focus too much on, nowadays. Your semi-unreadable, problem-passing code will not be worth much on an industry where people have to read, understand and maintain your code
Arthur
Competitive programming is usually done in one file, so it's really handy to use "using namespace std;" there, and it has no bad consequences since you are not going to maintain it in the long term
Anonymous
#include <stdio.h> #include<stdlib.h> void printList(); struct node{ int data; struct node *next ; }; struct node *head; int main(){ head = (struct node*)malloc(sizeof(struct node)); struct node * first = (struct node*)malloc(sizeof(struct node)); struct node *second = (struct node*)malloc(sizeof(struct node)); struct node *third = (struct node*)malloc(sizeof(struct node)); struct node *fourth = (struct node*)malloc(sizeof(struct node)); head ->data = 8; head->next = first; first->data= 2; first->next= second; second->data= 4; second->next= third; third->data = 3; third->next = fourth; fourth->data = 7; fourth->next = NULL; printList(); } void printList (){ printf("\n\n printing List delete(7):"); printf("\n\n printing List insert (9):"); printf("\n\n printing List:"); struct node *temp= head; while(temp!=NULL){ printf("%d,",temp->data); temp=temp->next; } printf("\n\n\n\n\n"); }
Anonymous
write functions: insertAtBeigning() insertAtEnd() deleteNode()
Anonymous
please help
Naol
is it a linked list
Naol
yeap
haven't you read the rules you can't write codes in here.
Anonymous
🆗
Naol
but i think the rule should be relaxed a little bit.
Naol
what kind of error are you having.
Naol
have you taken algorithm courses, you might have to put the algorithm on a paper first.
Anonymous
No, I took a data structure course
vinícius*
please help
With what? Is it crashing? Is it wrong?
vinícius*
Linked lists are an important concept, man. Do try to do this on your own. Once you understand what to do, it's gonna come quick
Naol
No, I took a data structure course
you should have taken algorithm along side, it is a necessary part of programming, there are a lot of concept which under it.
Naol
am i allowed to share book in here, it says in the rules, but the book has the content this guy needs.
vinícius*
The rules only prohibits piracy
vinícius*
If the book is free then I imagine it's ok
.....
Or you can upload this book in any cloud and share the link
Naol
it is on a telegram channel. it is free.
Naol
it is from tutorialspoint, before it becomes fully commercial.
Anonymous
And be banned
If the book is not free
Anonymous
https://www.youtube.com/watch?v=qejTqnxQRcw https://www.youtube.com/watch?v=qXleSwCCEvY
Mar!o
@SysMario, check it out
Thanks 😊 I'll watch it after work...
Anonymous
Macros
Mar!o
In C++ I used macros in Rust I use the #[cfg(target_feature = "sse4.1")] for SSE 4.1 for example.
Mar!o
Nah generally I make a function with abstracts it aways. Currently I have a module i32 for int and f32 for float with all "operators" overloaded but as functions. One wraps it all: #[inline(always)] pub fn add8(x: &mut [i32; 8], y: &[i32; 8]) { #[cfg(all(target_feature = "simd", target_arch = "x86_64"))] { #[cfg(target_feature = "avx")] { super::avx::i32::add8(x, y); } #[cfg(all(not(target_feature = "avx"), target_feature = "sse4.1"))] { super::sse::i32::add8(x, y); } #[cfg(not(any(target_feature = "sse4.1", target_feature = "avx")))] { super::fallback::i32::add8(x, y); } } #[cfg(not(all(target_feature = "simd", target_arch = "x86_64")))] { super::fallback::i32::add8(x, y); } }As you can see we have a fallback version.
V01D
#include<iostream> #include<cmath> using namespace std; //Let’s declare first any global constant, if any required // This variable is defined globally, i.e. it is known to all functions in this program as PI // To declare a global constant you must write it outside the main() function const double PI = 3.14159; //Now we declare any programmer defined function double cross_area(double r); // Function prototype for function cross_area double side_area(double r, double h); // Function prototype for function Side_area // Start defining the main function int main(void) { double h, r; //variables local to the main function cout « "Enter the radius and the height of the cylinder in Cm <Enter> "; cin » r » h; cout « endl; cout « "Before I do any computation or call any function, I want to let you know that \n"; cout « "you have entered r = " « r « " and h = " « h « "." « endl; cout « "I am planning to use inch, thus in the first function, I will convert r, and " « endl; cout « "in the second one I will convert h \n"; cout « "The cross section area of the cylinder is " « cross_area(r) « " inch-sqr" « endl; cout « "The side area of the cylinder is " « side_area(r,h) « " inch-sqr \n\n"; return 0; } // Definition of all programmer defined functions double cross_area(double r) { //Cross section area includes the disks at the bottom and the top r = r * 0.3937; // converting r to inch return 2*PI*pow(r,2); } double side_area(double r, double h) { double area; //variable local to side_area function h = h * 0.3937; // converting h to inch area = 2*PI*r*h; return area; }
Mar!o
And then I have submodules for SSE, AVX etc.. with also submodules for i32, f32 and in there there are the functions with intrinsics: #[inline(always)] pub fn mul16(x: &mut [i32; 16], y: &[i32; 16]) { unsafe { let x: *mut i32 = x.as_mut_ptr(); let y: *const i32 = y.as_ptr(); _mm_store_si128( x as *mut __m128i, _mm_mullo_epi32( _mm_loadu_si128(x as *const __m128i), _mm_loadu_si128(y as *const __m128i), ), ); _mm_store_si128( x.offset(4) as *mut __m128i, _mm_mullo_epi32( _mm_loadu_si128(x.offset(4) as *const __m128i), _mm_loadu_si128(y.offset(4) as *const __m128i), ), ); _mm_store_si128( x.offset(8) as *mut __m128i, _mm_mullo_epi32( _mm_loadu_si128(x.offset(8) as *const __m128i), _mm_loadu_si128(y.offset(8) as *const __m128i), ), ); _mm_store_si128( x.offset(12) as *mut __m128i, _mm_mullo_epi32( _mm_loadu_si128(x.offset(12) as *const __m128i), _mm_loadu_si128(y.offset(12) as *const __m128i), ), ); } }
Don Peter Joseph
i am using a structure pointer. how to pass it to a function
Don Peter Joseph
i know that. i am trying to pass pointer like display(p),where p is a pointer
Don Peter Joseph
pointer as an actual argument
Naol
it would pass the address
Ahmed
Hey guys I just want to know how long does it take to know everything in c++ I also want you to recommend me a good book.
Sai
what is the difference between getc(), getchar(), getch() and getche()
V01D
it would pass the address
No. & is the address. * is the value
V01D
Unless you use the & as a reference then things change a bit but I am still learning that
Rashu
When we use long long
V01D
When you need to have that much space available
Z0OM
is there any way to prevent user for defining an object like this. myClass s = myClass();. though myClass s(); is fine.
Roxifλsz 🇱🇹
Z0OM and V01D, hmmmm such interesting names
Dima
Roxifλsz 🇱🇹
At least not skids
That was not my point, but ok
Z0OM
ooh
Z0OM
thankyou
Parikshit
I'm using vs studio, for cpp, I am not able to run more than one source file in a project
Dima
Hmm okay
Parikshit
Anonymous
Create separate projects in one solution
V01D
/report