Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE DO AS SOON AS POSSIBLE To create a class, programming notes. -contain a p

ID: 3681037 • Letter: P

Question

PLEASE DO AS SOON AS POSSIBLE

To create a class, programming notes. -contain a pointer to a string, which should be used to keep track of a dynamic array of strings that will contain notes you think are important about programming material. -contain an integer value to keep track of the number of elements currently in your dynamic string array, and an integer value to keep track of the current capacity of the dynamic string array, -contain member functions to add a note, to modify a note based on its index, and to remove a note based on its index. -overload the input and output operators to work with the keyboard, the monitor, and files. -based on your knowledge of what needs to be done with classes with member data related to dynamic memory allocation, you will provide any additional necessary code.

Explanation / Answer

#include<iostream>
#include<stdlib.h>

using namespace std;

class Note{
       private:
           string *notes;
           int capacity;
           int count;
       public:
       // this is constructor that takes capacity as a parameter
       // this sets count, capacity and create a sting array dynamically
           Note(int cap){
                   capacity = cap;
                   count = 0;
                   notes = new string[capacity];
           }
          
           void add(string note){
                   // if notes array is not full
                   if(count != capacity){
                           notes[count] = note;
                           count++;
                   }
                   else{
                           cout<<"No space ";
                   }
           }
          
           void modify(string note, int index){
                   // if index value is under current count
                   if(index < count){
                           notes[index] = note;
                   }
                   else{
                       cout<<"Only "<<count<<" notes are available ";
                   }
           }
          
           void remove(int index){
                   if(index < count){
                       // deleting note at given index
                       for(int i=index; i<count-1; i++)
                               notes[i] = notes[i+1];
                       count--;
                   }
                   else{
                       cout<<"Only "<<count<<" notes are available ";
                   }
           }
          
           void printNotes(){
               cout<<"********************** ";
               for(int i=0; i<count; i++){
                          
                   cout<<notes[i]<<endl;      
               }
           }
          
           friend ostream &operator<<( ostream &output,Note &N ){
               //output << "F : " << D.feet << " I : " << D.inches;
               N.printNotes();
               return output;
           }

           friend istream &operator>>( istream &input, Note &N ){
               cout<<"Enter a notes to add"<<endl;
               string note;
               cin.ignore();
               getline(cin, note );
               N.add(note);
               return input;
           }
};

int main(){
      
       int capacity;
       cout<<"Enter capacity of notes: ";
       cin>>capacity;
      
       // creating Object of Note calss
       Note notes(capacity);
      
       cin>>notes;
       cin>>notes;
       cin>>notes;
       cout<<notes;
      
       notes.remove(0);
      
       cout<<notes;
      
      
       return 0;
}

/*

Output:

Enter capacity of notes: 5
Enter a notes to add
yest this is what you should do
Enter a notes to add
How are you ?
Enter a notes to add
pkk addwd dfefe
**********************
yest this is what you should do
ow are you ?
kk addwd dfefe
**********************
ow are you ?
kk addwd dfefe

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote