I have been learning c++ for about 1 month. So my problem is that suppose i have array[6]={10,-1,3,54,2,12}
I want to fill new array with {1,4,2,0,5,3}
because -1 is the lowest and its index is 1
2 is the lowest and its index is 4
3 is the lowest and its index is 2
10 is the lowest and its index is 0
12is the lowest and its index is 5
54 is the lowest and its index is 3
I want to sort from lowest to highest but using the index value. Here is what i have but the output i get is {1,4,2,4,5,5}
1,4,2 is right but then its wrong.
#include <iostream>
using namespace std;
void swap(int& v1, int& v2);
int main() {
const int size = 6;
int arry[6]={10,-1,3,54,2,12};
int sortedArry[6];
You are tracking the prices of some asset over time. The user will input a series of floating-point prices (e.g. 16.105 for sixteen dollars, ten and a half cents). When the user enters the price 0 (zero), output the overall minimum, mean, and maximum prices. Hint: there could be thousands or millions of prices to process, so do not try to store each one as it arrives, but keep a running total..
I've been using a while loop for user input, but I don't know how to get the last 0 that marks the end of the list to not be included in calculating the average.
I have a project where I have to schedule 3 doctors for 28 days. Doc A, B, and C. The rules are:
1. They can't work back to back, but only on weekends. Example Doc. A can't work Monday and Tuesday, If Doc. A works Saturday, he must work Sunday also. 2. Doc. A and B work alternate weekends. 3. Doc. C can't work Tuesday or weekends.
I'm trying to base my project off of the 8 Queens program that uses backtracking and the goto function. Right now, I'm just trying to get my program to print this
100100100 010010010 001001001
Here is my goto Code
#include "stdafx.h" #include <iostream> #include<iostream> using namespace std; void print(); #define n 28 //28 day schedule int a[n]={};
[Code] ....
If you look at my code you will notice that it prints out like this, where array c doesn't take in account for array a.
1010101010101 0101010101010 1010101010101
I need getting the program to modify a[], b[], and c[] when necessary. I should be able to change any array element to '1' and it will automatically fill in the schedule by itself. example
Is there any way to track what functions from what class are called at runtime? What I mean is a list of functions or classes which have been called at runtime.
I have code that creates an index file created from a data file of records.
#include <iostream> #include <fstream> #include <map> #include <sstream> #include <string> #include <iomanip> using namespace std; class Record {
[Code]...
I now need to write a second program that allows the user to enter a command on the Linux command line such as
search 12382 prog5.idx
and returns the information for the record with that key. The code I included for the index file is correct and works properly, but how to write the second program.
Here is the index file created by the first program:
I've been typed out a C program to let the user define the size of their string , and key in characters for this string , the program would then prompt the user for a character to search for in the string and return it's index value. Eg. Index of c in abc is 2. My code is as shown:
#include<stdio.h> #define SIZE 20 int search(char x[SIZE+1] , int n , char s); int main(void){ char x[SIZE+1] , s; int n , index;
[Code] ....
However , after I key in my characters for the string , the program does not prompt me to input a character to look for, it just prints it out and returns some funny number. But the program works just fine is I move this portion to the top :
printf("Enter alphabet to find: "); scanf("%c",&s);
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;
I'm writing a program of a stock market where i read from a file and sort with symbols and percent gain/loss. I have completed sorting with symbols but having trouble establishing the percent gain loss. First i designed and implemented the stock object. call the class stockType. main components of a stock are the stock symbol, stock price and number of shares. Second we have to create a list of stock objects. call the class to implement a list of stock objects stockListType. To store the list of stocks, i declared a vector and called the component type of this vector stockType. Because the company requires me to produce the list ordered by percent gain/loss, i need to sort the stock list by this component.
However, i'm not to physically sort the list by component percent gain/loss; instead i should provide a logic ordering with respect to this component. To do so i added a data member, a vector to hold the indices of the stock list ordered by the component percent gain/loss and i called this array indexByGain. I am going to use the array indexByGain to print the list. The elements of the array indexByGain will tell which component of the stock list to print next. I have trouble going about how to implement the function sortStockGain(). Below is my entire code and the txt file. I have sort symbols working but dont know how to implement the sort by gain.
I have to write a program that sorts numbers from least to greatest. The way that it has to sort them is:
1) The program assigns the first number to be a minimum 2) If the next number is less than the minimum is now that number and they switch places. (We keep on looking if the number next to it is not smaller) 3) The program also gets the index of the minimum number 4) We keep on going until it is in order.
// Sort.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include <iostream> #include <vector> using namespace std; void Sort(vector<int>&input); int _tmain(int argc, _TCHAR* argv[]){ vector <int> input;
i want to write an array sorting program that works with recursive function.but i can not do it.
my algorithm
Recursive find the min value find the min value and save it find the min value and save it and remove it from loop put the rest in loop again find the min value again .. ...
i didnt write the function because i dont know how will it work
Code:
#include<stdio.h> #include<stdlib.h> #define s 5 void main() { int a[s]={25,3,2,4,1},c[s]; // c[s] for new sorting int i,ek,j; //ek = min
I was trying to implement sorting in a linked list. However, when i run the sortList() function the program abruptly terminates. Here's the complete code:
Code: /* * { * SingleLinkedList.c * * Created on: 28-Nov-2014
I'm currently trying to code a sorting algorithm program.
let's asume I have a string given: aa, aaa, bbb, bas, zya!
I first of all want to split the given string on commas and '!' tells the program the string ends here and is no part of the last word. lower and upper case is not important at the moment. trying to implement everything with standard libary
output should be like that ofc: aa aaa bas bbb zya
I already looked into the bubble sort algorithm and I think it benefits my needs. Just wanted to know how I should start out with the string split.
I've got this sorting program that uses variables from another class but I'm not sure why its not recognizing it. I'm getting an error length and list not declared in this scope.
#include <iostream> #include "arrayListType.h" using namespace std; template<class elemType> class orderedArrayListType: public arrayListType<elemType> {
I am having an issue with my sort function. This is one part of the Hash table program. The main issue is that I am trying to sort the pointer table after all of the values have been entered. The ptr_sort function is not a class function and so I am therefore unable to use the class variables psize and pTable. Is there another way I should be trying this? it is a Vector should I use the sort() function from the vector class in STL?
I could trace the above one of the mistakes where the array initialization is crossing the array limits and writing into array[32] which is not available. My question does it overwrite into array1 as it is declared below array or it can write into any other location.
Code: using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Chapter7Problem13
[Code] .....
I keep getting an out of bounds error in my code
I'm suppose to enter number of orders then enter those orders then calculate a discount and net price display the orders, discount, net price then the totals at the bottom ....
I want to get the starting index of structure elements, whoz id are 0,1,2,3 Like in below code col_data[0] (starting id=0) col_data[3] (starting id=1) col_data[5] (starting id=2) col_data[8] (starting id=3) Code:
Code:
typedef struct gg{ int id; int value; }
[code]....
How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?
I need function to determine where to place new element in sorted array. I want to use binary search to find index where element should be placed, when push all others.
Prototype should be something like
int WhereToPlaceElement(ElementType hash); // uses private atribute ElType** elements
I have tried my best to write, but all tries ended in inf loops and reading invalid locations of array.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mind_Puzzle { public partial class Form1 : Form
[Code] .....
When i try to start it, it doesn't start or it gives an error on "UsedList[i] = false;".
The error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Mind Puzzle.exe
I am suppose to make a value to attach to a array and then have it stop on the last one with an error if it were to go past (done more or less).
Problem is I am suppose to use a int to hold the value of the array and then add 1 each time but my question is, if you were to add another number to increase your current array slot, what would that look like as I image that going array[0] + 1 isn't going to make it array[1].
I need understanding the logic behind this function. The function is supposed to "Return a pointer to the character at the index given" . For example, what exactly are we declaring at "(char * const c, int index)"? where does "index" come from or equal to in the body of the function?
Code: 1 2 3 4 5 6 7 8
char * GetValueAtIndex(char * const c, int index) { int i = 0; char *p = c; while (i++ != index) p++; return p; }