Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Wednesday, 4 December 2019

Write a program that has a declaration in main() to store the string "Vacation"

Q: Write a program that has a declaration in main() to store the string "Vacation" i near in an array named message. Also, add a function call to display() that accepts message in an argument named strng and then displays the contents of message by using pointer notation *(strng + i), modify the display() function to use the expressions *strng rather than *(strng + i). The program I compiled from this question is listed below, I am struggling with placements of notations on the latter part of the question.

#include <iostream>
using namespace std;

int main(){
void dispstr(char*);
char str[] = "Vacation";

display(str);
return 0;
}

void display(char* ps)
{
while( *ps )
cout << *ps++;
cout << endl;
}

Solution:

 #include <iostream>
using namespace std;

int main(){
void dispstr(char*);
char str[] = "Vacation";

display(str);
return 0;
}

void display(char* ps)
{
while( *ps )
cout << *ps++;
cout << endl;
}

Write a program that has a declaration in main() to store the string Vacation

Q: Write a program that has a declaration in main() to store the string Vacation is near in an array named message. Include a function call to display () that accepts message in an argument named string and then displays the contents of message by using the pointer notation *(strng + i).
Then modify the display() function written to use the expression *strng rather than *(strng +i) to retrieve the correct element.


Solution:

#include <iostream>

using namespace std;

void display(char* string)
{
for(int i=0; i<strlen(string); i++)
cout << *(string+i);
}

void display2(char* string)
{
int len = strlen(string);
for(int i=0; i<len; i++)
{
cout << *string;
string++;
}
}

int main()
{
char message[50] = "Vacation is near";


display(message);
cout << endl;
display2(message);
return 0;

Saturday, 23 November 2019

A bit string, 0111101111101111110, needs to be transmitted

Q: A bit string, 0111101111101111110, needs to be transmitted at the data link layer.
What is the string actually transmitted after bit stuffing?
 
Solution:
 
 The output is 011110111110011111010.