C++ :: Sorting Names And Numbers And Also Using Templates
May 7, 2013
For my project I have to sort 5 numbers and 5 names using a template bubble sort. I have one header for the numbers, and one for the names. This is what I have so far for my testing page:
#include "Floatheader.h"
#include "Nameheader.h"
#include <string>
int main ()
myFloat obj1;
myFloat obj2( 2.2, 5.1);
[Code] .....
I have to create a template to look like this: template<>....with a class inside the arrows. Then, I have to use bubble sort to sort the 5 names and number objects I have created. Sorting the names and numbers and also using templates?
i'm new to C++ i came across this bubblesort program earlier relating to class templates i was wondering how to make this into simple function templates
#include<iostream> #include<iomanip.h> #include<conio.h> #include<stdio.h> using namespace std; template <class t> class bubble
So I been asked to write a program that does the following:
Write a program that allows the user to enter a series of 10 names from the keyboard and then sorts and prints the names in alphabetical order. Use a series of functions:
1) Input the data 2) Sort the data (use a bubble sort) 3) Print the data
After this is done, allow the user to enter a name from the keyboard and determine if the name appears in the list. Use a function to accomplish the search. The name to be searched for should be input within main and sent to the function as an argument.
4) Search the data (use a binary search of type bool)"
this is whats I wrote so far and its giving me error with the sorting and the searching, I need to fix it and I cannot figure out how?!.
#include <iostream> #include <conio.h> #include <string> using namespace std; void bubbleSort(string[], int); int main()
I am at a lost of how to sort names in alphabetical order after having the user input them into a linked list. I manage to create a program that did have the person input names into the linked list and when it is printed it displays the names in the order of how the user inputted the names.
#include <cstdlib> #include <iostream> using namespace std; #include <string> class NodeType { public: string NodeValue;
A teacher has asked all her students to line up single file according to their first name. For example, in one class Amy will be in front of the line and Yolanda will be at the end.
Write a program that will read in a file of names. Names should be read until there are no more names to be read. Use LineUp.txt as a test file for your program.
Once all the names have been read in display which student will be at the front of the line and which one would be at the end of the line. You may assume that no two students have the same name.
These are the name in the LineUp.txt file if needed: Cooper Gavin Joseph Sierra Kacie Dylan Kaylee Will
I have a dataset which is a coauthorship network (a .txt file).I want to replace all the names of the authors with a unique number(no matter what the number is but it's important these numbers should be unique).
I've opened the dataset in excel then copy the author's names to another excel file,then I want to replace the authors names with their row numbers. what should i do?
I am trying to write a program that would convert numbers of base 10, decimal numbers, to binary or hexidecimal numbers, base 2 and base 16. I want the program to run a loop through the various numbers input and store each number converted to the new type in a separate variable with the same basic name but different last letters/digits to differentiate between them and add them to the total.
Basically, I'm saying that i have the user input a number and letters. Let's say 15, d, b. So they want to convert 15 of decimal type to binary.
The program would then take the variable used to hold that number, and the other to variables to decide what function to perform on the number.
Then I will already have a variable initialized for the 3 possible conversions (binaryKey[], decimalKey[], hexideciKey[])
Then I want it to convert it and store the number at different places in the array to form the final number. Although, there is no way to predict what number the user will input, so there is no way of knowing initially where the converted place-value will need to be placed in the array.
I was wondering if there was a way to have the program run a loop where as the progression continues, it appends a number to the end of a universal name for the variables and then adds them together in the correct order creating the sequence that means that number.
In simpler terms:
Input a number: 15 Input type of base: d Input converted type: b
Program then continually divides the number by 2, storing the remainder in a new variable
Such as: for(int i=1, i < (str(number).len), i++){ when i = 1, you would get int number1;
I'm trying to take a users input and break it up into four separate numbers, then take those numbers and arrange them from smallest to largest.So far I can't seem to get them working right.
Code:
# include <stdio.h>main () { int inputVariables[4]; //where userinput goes after being broken up int arrangedValues [4];// the user values arranged lowest to highest int i; int j; }
I have been working on this program for days now and for some reason my program will not write to my third file. It will call all of the integers that I need it to call but it will not write them out to a file. How to use my loop correctly.
#include <iostream> #include <fstream> using namespace std;
But how would I do this using parallel_for_each (C++AMP) ? I need this for some algorithm that works with very long arrays and I think GPU would do this faster than CPU (even if I use all threads).
My program reads a string of characters. Prints all occurrences of letters and numbers, sorted in alphabetical and numerical order. Letters will be converted to uppercase.Other characters are filtered out, while number of white spaces are counted.
The problem is it crashes when i run the program. Here is my code
#include <iostream> const int SIZE = 100; using namespace std; int main() { char *pStr, str[SIZE] = "", newStr[SIZE] = "", ch; int count = 0, i = 0, j;
I'm writing a simple program to sort numbers through use of a pointer. I've always been bad with pointers, and I tried to use a typical temp value to hold the value, but i feel like I am over doing it.
#include <iostream> using namespace std; void SortTests(int *, int); int main() { int *ptr; int tests;
I'm trying to make a number sorting program with other features, but the numbers are all wrong.
#include <iostream> #include <iomanip> #include <fstream> using namespace std; void readData(int list[], int size); int main() { int size = 50; int scores[50] = {0};
i have a vector of stores. i would like to delete the specified choice(store) from the list. Here is what i have but my erase statement is wrong and wont compile.
void Store::deleteSpecifiedStoreFromList(string choice) { for (int i = 0; i < this->stores.size(); i++) { if(this->stores[i].getStoreNames() == choice) { this->stores.erase( std::remove_if( this->stores.begin(), this->stores.end(), choice ), this->stores.end() ); } } }
We've only covered up to Functions and how to use reference variables inside the function parameter.
One of the hw problem that was assigned was to write a void function that takes three parameters( num1, num2, num3) by reference and sorts their values into ascending order, so that num1 has the lowest, num2 the middle value, and num3 the highest value. For example, if user enters: 14, -4, 8, then the output should look like this:
-4 8 14
I've completed the program with a bunch of if/ else if statements but I was wondering if there was a more efficient way to sort the numbers. Bear in mind, we've only covered materials up to functions so I can't use any other new techniques that we haven't cover yet. Here is my code:
// This program will take three int parameters by reference and sorts their value into ascending order //so that num1 has the lowest value, num2 has the middle value, and num3 has the highest value #include <iostream> using namespace std; // declare function with reference parameter that with sort numbers void sortNum(int &, int &, int &); int main () {
I am a beginner at C++, the output is pretty self explanatory. I'm trying to make a number sorting program with other features, but the numbers are all wrong.
Code: #include <iostream> #include <iomanip> #include <fstream> using namespace std;
What kind of code should i use for sorting numbers in both ascending and descending order? I don't know how to use bubble sorting either, is there another easy way to sort this out?
My program reads a string of characters. Prints all occurrences of letters and numbers, sorted in alphabetical and numerical order. Letters will be converted to uppercase.Other characters are filtered out, while number of white spaces are counted.
the problem is it crushes when i run the program
Here is my code
#include <iostream> const int SIZE = 100; using namespace std; int main() { char *pStr, str[SIZE] = "", newStr[SIZE] = "", ch; int count = 0, i = 0, j;