473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

I want to re-arrange elements depending on input

I am creating a program that should allow user to enter Top 20 hit songs.
The user should enter song name and artist name in order of position.The output should be printed in table format and should be allow user to re-arrange songs later if she want to do so.
The user has to enter song name and the new position she wants the song moved to (this means she chooses from the 20 filled positions).For example if the user want to take a song from position10 to position1, the song will make the song in position1 move one position down and the same to the rest of the song

So the problem I have is how to make this work, i have a little knowldge in sorting arrays of which I think could help. Can Someone help me copmlete the following code:

Expand|Select|Wrap|Line Numbers
  1. //last part of the code
  2. //print data
  3.  for int pos=0;pos<20;pos++
  4. cout<<setw(5)<<(pos+1)<<setw(15)<<song[pos]<<setw(15)<<artist[pos]<<endl;
  5.  
  6. //here i need to tell the program to move songs one step up or down depending on user choice
Oct 29 '10 #1
1 1559
weaknessforcats
9,208 Expert Mod 8TB
I see you are using cout so that means you are using C++.

That being the case, I recommend you use the C++ Standard Library list<> template for your database. Use C++ string objects for your data fields.

All of the moving around you need to do is already coded in this list<> template, which implements a double-linked list.

To make things easy, declare a struct to contain your data items and make a lst of variables of that struct.

When you sort, you can write a function that compares two of your struct variables and returns a true if the first argument is greater than the second aregument and false otherwise. Then you can use the C++ Standard Library sort<> template. You use iterators to the start and end of the list plus the address of your compare function. Voila! your list is sorted.

Almost all C++ textbooks have examples of how to do exactly this.
Oct 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Michele Simionato | last post by:
I think I want "re-entrant exceptions" (not sure if this is the correct name). Consider the following example: class NotSeriousException(Exception): pass def do_this(): raise...
4
by: Greg Brant | last post by:
i have a news system which runs off the id of the news item, the system allows the owner to delete a record if the wish, this removes the record from the database taking with it that...
4
by: Muhd | last post by:
It seems like im missing something, what i want to do is select the last row from a table that relates to a specific person. My table and select statement follow, the select statement works fine,...
9
by: Tony Johansson | last post by:
Hello! Some information to be able to have a change to answer the question. Assume I have a large system developed in MFC. In this system we have only C++ code so no other language exist. This...
12
by: DavidS | last post by:
Is there an equivalent ShellExecute() command (like in VB/VC apps) for opening up Excel files from within ASP.NET web application. I create an Excel format of a crystal report. I'd like to next...
4
by: DaveOnSEN | last post by:
I love how easy it is to develop ASP.NET user controls. They are fast to make and easy to reuse within your web application. However, sometimes I want to make controls that I use in one web...
10
by: vertigo | last post by:
Hello I need to use some regular expressions for more than one line. And i would like to use some modificators like: /m or /s in perl. For example: re.sub("<script.*>.*</script>","",data) ...
85
by: pereges | last post by:
#include <stdio.h> typedef struct { double x, y, z; }vector; int main(void) { int i;
11
by: Web Search Store | last post by:
Hello, I set up a web page with 2 user controls. In classic asp, the first one did all the declarations, and the second one used the values, and could reset it. In ASP.Net so far I can't...
6
by: Pat | last post by:
I have a regexp in Perl that converts the last digit of an ip address to '9'. This is a very particular case so I don't want to go off on a tangent of IP octets. ( my $s = $str ) =~...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.