Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7071785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:43:47+00:00 2026-05-28T05:43:47+00:00

So, I know some Python but I thought that I should try to add

  • 0

So, I know some Python but I thought that I should try to add some c++ to that knowledge. This is the code I’ve written that I’m playing with (it’s actually a rewrite of some python code). It adds some song data to a class (or a multidimensional array inside a class). So far so good. Most of it work. But I’m stuck at the delSong method. I don’t think I could implement this with arrays, so It’s seems like I’m at a dead end. I read a little about vectors, but they won’t let med delete an item in the middle. How could I get further? Shall I abandon arrays for something else? But what would that be?

#include <iostream>
#include <string>

using namespace std;

class Jukebox{
public:
  void addSong(string artist, string title, string filename) {
    songs [songsCounter][0] = artist;
    songs [songsCounter][1] = title;
    songs [songsCounter][2] = filename;
    songsCounter++;
  }

  void printSong (int song) {
    cout << songs[song][0] << " - ";
    cout << songs[song][1] << " : ";
    cout << songs[song][2] << endl;
  }

  void printSongs () {
    int song;
    for (song=0; song<songsCounter; song++ ) {
      cout << songs[song][0] << " - ";
      cout << songs[song][1] << " : ";
      cout << songs[song][2] << endl;
    }
  }

  void delSong(int song) {
    // Some code here
  }

private:
  int songsCounter;
  string songs [512][3];
};

int main() {
  Jukebox jbox;
  jbox.addSong("U2", "Magnificent", "U2-Magnificent.mp3");
  jbox.addSong("Sting", "Englishman in New York", "Sting-Englishman_in_New_York.mp3");
  jbox.addSong("U2", "One", "U2-One.mp3");
  jbox.printSongs();
  return 0;
}

In my python code I actually using an in memory sqlite3 db. But I could as well write it with a simple list of tuples. And that is a similar approach to what I’m trying to do here. But an in memory sqlite database would also be a possible way for me to do this in c++. But it does’nt look very easy either to implement?

One more thing, I also want to add a sort method later so please have that in mind when you suggest a solution so I don’t get to another dead end… 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:43:48+00:00Added an answer on May 28, 2026 at 5:43 am

    Vectors do allow deletion in the middle (look for the erase function), albeit not at the greatest speed.

    I’d recomend using a vector of structures instead of a multidimensional array.

    struct song {
        string artist;
        string title;
        string filename;
    };
    

    And then in your Jukebox:

    vector<song> songs;
    

    The vector grows as needed and keeps track of its own size, contrary to the array.

    For sorting, there’s std::sort function in the <algorithm> header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is bit of a general question but I wanted to know some different
I already know Java, Objective C, C#, and some Python. I want to be
Possible Duplicate: Reading/Writing MS Word files in Python I know there are some libraries
to start off, I know C++, C#, Python, some Ruby, and basic Javascript. Anyway,
I know some languages allow this. Is it possible in C++?
Do you know some neat Java libaries that allow you to make cartesian product
I do know some basic differences but there are still some questions in my
I have written some physics simulation code in C++ and parsing the input text
I have a python script which should parse a file and produce some output
I'm writing some mail-processing software in Python that is encountering strange bytes in header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.