حماد
So maybe I am right 😁
AHMED
#include<iostream> #include<vector> using namespace std; int main(){ vector<int> marks ={55, 78, 98, 34, 54, -53, 0}; cout<<"The original data are:\n"; for (auto el : marks){ cout<<el<<"\n"; } cout<<"The new data are:\n"; for (auto el : marks){ return el+2; } for (auto el : marks){ cout<<el<<"\n"; } return 0; }
AHMED
The original data are: 55 78 98 34 54 -53 0 The new data are: [Program finished]
AHMED
How to make the program add 2 to each element in the vector by making a new vector? And by changing the original vector?
Vlad
Or just a range based for
AHMED
How?
Vlad
How?
https://en.cppreference.com/w/cpp/algorithm/transform
Vlad
There's an example at the bottom
AHMED
I did it :
AHMED
#include<iostream> #include<vector> using namespace std; int decrement(int x){ return x-1; } int main(){ vector<int> marks ={55, 78, 98, 34, 54, -53, 0}; vector<int> degrees; cout<<"The original data are:\n"; for (auto el : marks){ cout<<el<<"\n"; } transform(marks.begin(), marks.end(), marks.begin(), decrement ); cout<<"The new data are:\n"; for (auto el : marks){ cout<<el<<"\n"; } return 0; }
AHMED
The problem now is that when I store the new data in a new vector called degrees And making a range based for loop to cout the members of vector degrees , there is a segmentation fault. How to solve this?
AHMED
#include<iostream> #include<vector> using namespace std; int decrement(int x){ return x-1; } int main(){ vector<int> marks ={55, 78, 98, 34, 54, -53, 0}; vector<int> degrees; cout<<"The original data are:\n"; for (auto el : marks){ cout<<el<<"\n"; } transform(marks.begin(), marks.end(), degrees.begin(), decrement ); cout<<"The new data are:\n"; for (auto el : degrees){ cout<<el<<"\n"; } return 0; }
AHMED
The original data are: 55 78 98 34 54 -53 0 Segmentation fault [Program finished]
Vlad
That is what to use if you want to populate a vector
Anonymous
Write a C++ program that creates a text file named my_first_file.txt which contains the following string “We have final exam today, and i am best programmer”. Write a function named filter_words() that reads the file my_first_file.txt and creates a new file my_second_file.txt that will contain only those words from file my_first_file.txt which starts with a lower case vowel words Hint: First file text = We have final exam today, and i am best programmer Second file text = exam and  i am
Anonymous
Anybody help me??
klimi
Anybody help me??
what do you need help with? (you don't want us to write the code do you?)
Anonymous
No
Anonymous
Please help me
AHMED
I wrote this . And it worked
AHMED
#include<iostream> #include<vector> using namespace std; int decrement(int x){ return x-1; } int main(){ vector<int> marks ={55, 78, 98, 34, 54, -53, 0}; vector<int> degrees; cout<<"The original data are:\n"; for (auto el : marks){ cout<<el<<"\n"; } transform(marks.begin(), marks.end(), back_inserter(degrees), decrement ); cout<<"The new data are:\n"; for (auto el : degrees){ cout<<el<<"\n"; } cout<<"The original data again are:\n"; for (auto el : marks){ cout<< el<<"\n"; } return 0; }
Hanz
At the first glance i saw the function decrement, i think it is redundant. But then i saw it being used in transform method 😂😅
Hanz
Ah, nevermind
Iqbal
Hi Can someone share what are the common interview question for embedded software engineer? Thank you ☺️
MAC
1. The Synchronous Transmitter Creates files of bits (‘0’ and ‘1’ characters) from the input files. All valid input files contain data made up of ASCII characters and have the .inpd file extension. The data to be transmitted must be structured as a set of blocks. Each block will consist of 2 SYN characters, ASCII 22, one control character to indicate the length of data block followed by a maximum of 64 data characters. Assume that there are no trailing control characters. Every block transmitted must contain 64 data characters except possibly the case where the remainder of the file cannot fill the buffer. Each character will consist of 7 information bits and a parity bit. These bits will be transmitted from the least significant bit (LSB) to the most significant bit (MSB). The table below illustrates the structure of a block created to transmit the “Hello!” character string. The actual contents of this block has to be encoded with characters ‘0’ and ‘1’ to simulate the binary representation of the characters used.   2222 6 Hello!     2. The Synchronous Receiver This program reads the files created by the Transmitter (.binf) as input, checks for transmission errors, decodes stream of bits, and stores the resulting information on a file (.outf).   Both programs should have three distinct layers: physical, data link and application. The physical layer should contain routines to handle jobs such as converting a character into a binary bit pattern, calculating, and including a parity bit, executing the cyclic redundancy check and writing bits into an output file (i.e., transmission of bits). It should also include routines for reading bits from a file (i.e., reception of bits) and converting bits into characters. The data link layer should contain routines for framing (putting two SYN characters, a LENGTH character, and data into a frame) and deframing (separating those control characters from data characters). The application layer should contain routines to handle tasks such as reading data to be transmitted from input data file in the Transmitter and writing received data into display (or output data file) in the Receiver, as well as any other routines that you feel necessary.  Your solution must also include a module to simulate transmission errors.   3. Details The following are the tasks to be done for this project: a.      Create a simple client/server (transmitter/receiver; consumer/producer) application as discussed in this document that uses a simple odd parity bit and a file for "data transmission". b.     Design and implement the Error Creation module. This component must, in a random way, change a single bit as well as more than one bit in the message. Your function must have the number of bits that are to be modified as an input parameter. It must also inform the user the frame, byte and bit locations of the errors introduced. The receiver must be able to report the location of errors introduced during transmission.    ...here's the low down
Are you going to work in Google or Apple ?
AHMED
#include<iostream> #include<vector> using namespace std; int main(){ vector<int> marks ={55, 78, 98, 34, 54, -53, 0}; cout<<"The original data are:\n"; for (auto el : marks){ cout<<el<<"\n"; } cout<<"The new data are:\n"; for (auto el : marks){ cout<< el+2; } return 0; }
AHMED
This is the output:
AHMED
The original data are: 55 78 98 34 54 -53 0 The new data are: 57801003656-512 [Program finished]
AHMED
Ok Thank u
AHMED
It worked
Aakash
AHMED
\n🙃
Yes I realized I missed \n after I printed the program here😂
Ugochukwu
Hi
robherc
Please help me
read each word from the file; compare the first letter to 'a' 'e' 'i' 'o' 'u' 'y'; then output to 2nd file if comparison /=0
robherc
1. The Synchronous Transmitter Creates files of bits (‘0’ and ‘1’ characters) from the input files. All valid input files contain data made up of ASCII characters and have the .inpd file extension. The data to be transmitted must be structured as a set of blocks. Each block will consist of 2 SYN characters, ASCII 22, one control character to indicate the length of data block followed by a maximum of 64 data characters. Assume that there are no trailing control characters. Every block transmitted must contain 64 data characters except possibly the case where the remainder of the file cannot fill the buffer. Each character will consist of 7 information bits and a parity bit. These bits will be transmitted from the least significant bit (LSB) to the most significant bit (MSB). The table below illustrates the structure of a block created to transmit the “Hello!” character string. The actual contents of this block has to be encoded with characters ‘0’ and ‘1’ to simulate the binary representation of the characters used.   2222 6 Hello!     2. The Synchronous Receiver This program reads the files created by the Transmitter (.binf) as input, checks for transmission errors, decodes stream of bits, and stores the resulting information on a file (.outf).   Both programs should have three distinct layers: physical, data link and application. The physical layer should contain routines to handle jobs such as converting a character into a binary bit pattern, calculating, and including a parity bit, executing the cyclic redundancy check and writing bits into an output file (i.e., transmission of bits). It should also include routines for reading bits from a file (i.e., reception of bits) and converting bits into characters. The data link layer should contain routines for framing (putting two SYN characters, a LENGTH character, and data into a frame) and deframing (separating those control characters from data characters). The application layer should contain routines to handle tasks such as reading data to be transmitted from input data file in the Transmitter and writing received data into display (or output data file) in the Receiver, as well as any other routines that you feel necessary.  Your solution must also include a module to simulate transmission errors.   3. Details The following are the tasks to be done for this project: a.      Create a simple client/server (transmitter/receiver; consumer/producer) application as discussed in this document that uses a simple odd parity bit and a file for "data transmission". b.     Design and implement the Error Creation module. This component must, in a random way, change a single bit as well as more than one bit in the message. Your function must have the number of bits that are to be modified as an input parameter. It must also inform the user the frame, byte and bit locations of the errors introduced. The receiver must be able to report the location of errors introduced during transmission.    ...here's the low down
It is not reasonable to expect us to even bother reading this giant wall-of-text post. The intent of the request to you is that you ISOLATE A SPECIFIC PROBLEM you are having, then give us the specific details pertinent to only the part you're needing help with.
robherc
#howtoask
Logan
Where to learn advanced c++ any ideas ???
J
Do you know the basic C++ stuff?
Logan
Ya
J
It can be reading book or find a lecture.
J
Depending which kind you prefer.
Logan
I'm good with them but to get placed intermediate level is needed
Logan
So I wanted to know what it needs to be a intermediate level c++ programmer
J
Ok. I see, it again depending on the definition of *intermediate and advanced*.
J
In book you can check move semantic, smart pointer, ownership. I define them as intermediate.
J
About C++20, you can check cppconference videos.
MAC
So I wanted to know what it needs to be a intermediate level c++ programmer
Base knowledge of os, compt architecture, algorithms and structures
Logan
In book you can check move semantic, smart pointer, ownership. I define them as intermediate.
Oh thanks ,I don't know what they are but I will be trying to learn them
Logan
Base knowledge of os, compt architecture, algorithms and structures
I'm familiar with data structures just need to practice them more
Logan
Base knowledge of os, compt architecture, algorithms and structures
Os base ,does that mean what is process ,child process , parent process , fork function ,pipes
J
I think so.
J
Learning C++ doesn't directly relate OS. But the C++ projects are also so.
MAC
Os base ,does that mean what is process ,child process , parent process , fork function ,pipes
#include <iostream> #include <chrono> #include <thread> using namespace std; int lav; int left(int p) { return (p*2+1); } int right(int p) { return(p*2+2); } void rec(int *p,int x, int size) { int l = left(x); int r = right(x); if(l < size and p[l] > p[x]) { lav = l; } else lav = x; if(r < size and p[r] > p[lav]) { lav = r; } if(lav != x) { int o = p[lav]; p[lav] = p[x]; p[x] = o; rec(p,lav,size); } } int main(int argc, char *argv[]) { int mass[21]; for(int p = 0; p <= (sizeof(mass) /4);p++) { mass[p] = rand() % 100; }; int p = 1; int size = ((sizeof(mass) /4) /2); int size2 = (sizeof(mass) /4)-1; for(int i = size; i>= 0;i--) { rec(mass,i,(sizeof(mass)/4)); } cout << endl; cout << "-------------------------------" << endl; for(int q = size2; q>= 1;q--) { int variable = mass[0]; mass[0] = mass[q]; mass[q] = variable; for(auto qq:mass) { cout << qq << " "; } this_thread::sleep_for(chrono::milliseconds(3000)); cout << endl; rec(mass,0,q); } }
Logan
Ya I want to be a c++ developer I have a experience of years with c++ introductory part but really when I see some of c++ code I think I have to learn this But don't know where to start
J
I think it is a binary heap. :D
Mohannad
بخ
MAC
Ya I want to be a c++ developer I have a experience of years with c++ introductory part but really when I see some of c++ code I think I have to learn this But don't know where to start
It's code for is Linux #include <sys/msg.h> #include <sys/types.h> #include <stdio.h> #include <iostream> #include <sys/ipc.h> #define IDOFSHM 2021 #define PM 1 #define IDOFRCV 2 #define MASSIZE 120 struct message_t{ int type; char string [MASSIZE]; }; int main(int argc, char *argv[]) { int f; if((f = fork()) == 0) { char s[MASSIZE]; int p; struct message_t mymessage; if((p = msgget(IDOFSHM,0))) { printf("Произошла ошибка создания очереди"); exit(-1); } while(1) { scanf("%s",s); if(strlen(s) != 1) { mymessage.type = PM; strcpy(mymessage.string,s); } else mymessage.type = IDOFRCV; if(msgsnd(p,&mymessage,sizeof(mymessage),0) != 0) { printf("%s","error"); exit(-1); } if(strlen(s) == 1) break; } } else if(f > 0) { printf("i am parent"); } else { printf("error"); } exit(-1); }
Logan
?
Logan
I just know basic theory part of Os
MAC
Parent tree
no, it's IPC between any 2 process
MAC
Parent tree
But for this parent -> child
J
Is there any recommendation of a C++ online lecture?
Logan
Is there any recommendation of a C++ online lecture?
I was to ask this any online tutorial which can help a basic level programmer to level up
Logan
?
robherc
Is there any recommendation of a C++ online lecture?
https://www.youtube.com/watch?v=0Cim_ZAj7xE https://www.youtube.com/watch?v=_bYFu9mBnr4
Adnan
Hy
Nameful
Bruh
MostaFa
Hi guys, I am learning Qt and now I am in the first steps. how do you think about Qt software? Do you think being professional in Qt can help us to finding a job?