Question

In: Computer Science

using c++ classes write program in which CString is used, and give simple and easy examples...

using c++ classes
write program in which CString is used, and give simple and easy examples in the form of program, to show how to use different CString function, use comments to explain what happened at that function.

Solutions

Expert Solution

#include <iostream>
#include <cstring>
using namespace std;
class CstringLL
{
    public:
    void find_char()
    {
        //memchr is used to check whether the given char is there in first specified number of characters in a string
   char str[]="Hello World";
   char c='o';
   int count=6;
   //if character is found it will return the location of the character to
   //be searched otherwise it will return null pointer
   if(memchr(str,c,count)) 
   {
       cout<<"the character "<<c<<" is present in first "<<count<<" at position "<<memchr(str,c,count);
       cout<<"\n";
   }
   else
   {
       cout<<"Not found\n";
   }
    }
  void cmp_strings(){
      // memcmp() is used to check whether  two strings contain same 
   //specified number of characters
   //count defines max no. of bytes to be check
   int count=6;
   char a[]="Hi my name is aman";
   char b[]="Hi my name is rahul";
   //if character in a at specifies count is greater then b then return positive value..
   //if character in a is smaller then in characters of b at specified count return negative value else return 0 when two string are same at specified count
   int r=memcmp(a,b,count);
   if(r==0){cout<<"two string has same first "<<6<<" characters";}
 }
 void cpy_str(){
     cout<<"\n";
     int a[5]={1,2,3,4,5};
     int b[5];
     memcpy(b,a,sizeof(int)*3);
 //copying only specified number i.e. 3 from array a in another array b
     for(int i=0;i<3;i++) cout<<b[i]<<" ";
 }
 void compare()
 {
     char a[]="Hello";
     char b[]="by";
     if(strcmp(a,b))
     {
         cout<<"\ndifferent string";
     }
     else
     cout<<"\n two string are same";
 }
 void find_length(char s[10])
 {
     cout<<"\n";
     cout<<strlen(s);
 }
 void char_ntimes(){
    //storing particular character in specified times
     char d[10];
     char c='o';
     memset(d,c,6);
     cout<<"\n";
     cout<<d;
    cout<<" storing char 6 times";
 }
 void split_string(){
   // splitting string on the basis of delimeter
     char n[]="apple mango orange pineapple";
     char delimeter[]=" ";
     char *r=strtok(n,delimeter);
     cout<<"\n";
     while(r)
     {
         cout<<r<<" ";
         r=strtok(NULL,delimeter);
     }
 }
};

  int main()
{
   CstringLL cl;
   cl.find_char(); // search for char
   cl.cmp_strings(); //compare strings
   cl.cpy_str(); // copy specified amount of data
   cl.compare();
   char s[]="Hello";
   cl.find_length(s);//find length of string
   cl.char_ntimes();// storing character n times in destination string
   cl.split_string();//spliting the string on the basis of delimeter
   return 0;
}  

Screenshot-


Related Solutions

Simple code please thats easy to follow. C++ Write a program that can be used to...
Simple code please thats easy to follow. C++ Write a program that can be used to compare Insertion Sort, Merge Sort and Quick Sort. Program must: Read an array size from the user, dynamically an array of that size, and fill the array with random numbers Sort the array with the Insertion Sort, MergeSort and QuickSort algorithms studied in class, doing a time-stamp on each sort. Use your program to measure and record the time needed to sort random arrays...
In C Programming, Thanks Many user-created passwords are simple and easy to guess. Write a program...
In C Programming, Thanks Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string. You may assume that the string does not contain spaces and will always contain less than 50 characters. i becomes ! a becomes @ m becomes M B becomes 8 o becomes . Ex: If the input...
Please, write this code in c++. Using iostream and cstring library. Write a function that will...
Please, write this code in c++. Using iostream and cstring library. Write a function that will delete all words in the given text that meets more that one time. Also note than WORD is sequence of letters sepereated by whitespace. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000 symbols with whitespaces. Each word is not longer than 30 symbols. Output: Formatted text. example: input: Can you can the can...
Please, write code in c++. Using iostream and cstring library Write a function that will find...
Please, write code in c++. Using iostream and cstring library Write a function that will find and return most recent word in the given text. The prototype of the function have to be the following void mostRecent(char *text,char *word) In char *word your function have to return the most recent word that occurce in the text. Your program have to be not case-sensitive(ignore case - "Can" and "CAN" are the same words) Also note than WORD is sequence of letters...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions with arguments. Create programs with small functions where main goes to a series of functions where the real work takes place. Don’t use global variables and don’t use break within a loop (unless working with a switch statement). Functions can’t have more than 30 statements of code, not including comments, blank lines, or variable definitions. Don’t use a return in the middle of the...
Write a C++ program that will be an information system for Oregon State University using classes...
Write a C++ program that will be an information system for Oregon State University using classes as well as demonstrating a basic understanding of inheritance and polymorphism. You will create a representation of an Oregon State University information system that will contain information about the university. The university will contain a name of the university, n number of buildings, and m number of people. People can be either a student or an instructor. Every person will have a name and...
Write a C++ program that will be an information system for Oregon State University using classes...
Write a C++ program that will be an information system for Oregon State University using classes as well as demonstrating a basic understanding of inheritance and polymorphism. You will create a representation of an Oregon State University information system that will contain information about the university. The university will contain a name of the university, n number of buildings, and m number of people. People can be either a student or an instructor. Every person will have a name and...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until...
Your objective is to write a well-documented simple program using classes, a loop, and nested ifs...
Your objective is to write a well-documented simple program using classes, a loop, and nested ifs to simulate an ATM using JAVA. 1. Create an ATM class with class variables name, pin, and balance, a constructor with parameters to assign values to the three instance variables, methods to get the name, pin, and balance, and methods to handle validated deposits and withdrawals ( deposit and withdrawal amounts cannot be negative, and withdrawal amount must not be greater than the existing...
Your objective is to write a well-documented simple program using classes, a loop, and nested ifs...
Your objective is to write a well-documented simple program using classes, a loop, and nested ifs to simulate an ATM using JAVA. 1. Create an ATM class with class variables name, pin, and balance, a constructor with parameters to assign values to the three instance variables, methods to get the name, pin, and balance, and methods to handle validated deposits and withdrawals ( deposit and withdrawal amounts cannot be negative, and withdrawal amount must not be greater than the existing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT