Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // arrays and stuff.cpp : Defines the entry point for the console application.
- // set your worsecase/bestcase scenerio. 20% movement either way.
- // standard deviation
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <conio.h>
- #include <fstream>
- #include <iomanip>
- #include <algorithm>
- #include <vector>
- using namespace std;
- void showValues (int [], int); // Function prototype. To define a function that takes an array parameter,
- // use empty [] for array argument.
- void lab8ArrayFiller (int [], int, int);
- void lab9sort (char [], char [], char [], char [], int);
- bool lab9alphabetical (char [], char [], int);
- int _tmain(int argc, _TCHAR* argv[])
- {
- const int ARRAY_SIZE = 8;
- int numbers[ARRAY_SIZE] = {5, 10, 15, 20, 25, 30, 35, 40};
- showValues (numbers, ARRAY_SIZE); // To pass an array to a function, just use the array name. It is common to pass array size
- // so that function knows how many elements to process.
- cout << numbers[0] << endl; // Array names in functions are like reference variables - changes made to array in a function
- // are reflected in actual array in calling function.
- /*
- #define infile "numbertest.txt"
- ifstream ins;
- ins.open(infile);
- int count = 0;
- const int arraySize = 4;
- double arrayCad [arraySize];
- double arrayUsd [arraySize];
- double arrayInt [arraySize];
- double arrayBond [arraySize];
- while (count < arraySize && ins >> arrayCad [count])
- {
- cout << arrayCad [count] << endl;
- count = count + 1;
- }
- count = 0;
- cout << endl << endl;
- while (count < arraySize && ins >> arrayUsd [count])
- {
- cout << arrayUsd [count] << endl;
- count = count + 1;
- }
- count = 0;
- cout << endl << endl;
- while (count < arraySize && ins >> arrayInt [count])
- {
- cout << arrayInt [count] << endl;
- count = count + 1;
- }
- count = 0;
- cout << endl << endl;
- while (count < arraySize && ins >> arrayBond [count])
- {
- cout << arrayBond [count] << endl;
- count = count + 1;
- }
- ins.close();
- cout << endl << endl;
- */
- //*******************************************************************************************
- //sort(array1, array1 + arraySize);
- /*
- while (array1 [0] > array1 [1] || array1 [1] > array1 [2] || array1 [2] > array1 [3])
- {
- count = 0;
- int temp = 0;
- while (count < (arraySize - 1))
- {
- temp = array1 [count];
- if( array1 [count] > array1 [count + 1])
- {
- array1 [count] = array1 [count + 1];
- array1 [count + 1] = temp;
- }
- count = count + 1;
- }
- }
- */
- //*******************************************************************************************
- /*
- #define infile2 "numbertest2.txt"
- ifstream ins;
- ins.open(infile2);
- struct Asset
- {
- vector <double> allocation; //asset allocation percentage
- vector <string> name; //fund name
- vector <string> symbol; //ticker symbol
- vector <string> geo; //geography
- };
- struct Asset sector1;
- while (!ins.eof())
- {
- double temp = 0;
- ins >> temp;
- sector1.allocation.push_back(temp);
- }
- sector1.allocation.resize(10);
- cout << sector1.allocation[0] << endl;
- cout << sector1.allocation[1] << endl;
- cout << sector1.allocation[2] << endl << endl;
- sector1.geo.push_back("Canada");
- cout << sector1.geo[0] << endl << endl;
- */
- ///////////////////////////////////////////////////////////////////
- //An array of a structure
- /*
- Asset assortment[10];
- assortment[0].name.push_back("bassi");
- cout << assortment[0].name[0] << endl;
- */
- ///////////////////////////////////////////////////////////////////
- //lab 8. Write a program to find the largest odd number in a 50-element array of integers
- /*
- #define infile3 "lab8.txt"
- ifstream ins;
- ins.open(infile3);
- int lab8 [50];
- int largest = 0;
- for (int count = 0; count < 50; count++)
- {
- ins >> lab8[count];
- }
- for (int count = 0; count < 50; count++)
- {
- if (lab8[count] % 2 == 0)
- {
- lab8[count] = 0;
- }
- }
- for (int count = 0; count < 50; count++)
- {
- if (lab8[count] > largest)
- {
- largest = lab8[count];
- }
- }
- ins.close();
- cout << largest << endl;
- */
- ///////////////////////////////////////////////////////////////////
- // Assume that your computer has the very limited capability of being able to read and write only single-integer digits
- /*
- #define infile4 "lab8_digits1.txt"
- #define infile5 "lab8_digits2.txt"
- ifstream ins;
- int number1 [30];
- int number2 [30];
- int result [30];
- int digitsCounted = 0;
- int carryDigit = 0;
- ins.open(infile4);
- while (!ins.eof())
- {
- ins >> number1[digitsCounted];
- digitsCounted = digitsCounted + 1;
- }
- ins.close();
- lab8ArrayFiller (number1, 30, digitsCounted);
- digitsCounted = 0;
- ins.open(infile5);
- while (!ins.eof())
- {
- ins >> number2[digitsCounted];
- digitsCounted = digitsCounted + 1;
- }
- ins.close();
- lab8ArrayFiller (number2, 30, digitsCounted);
- for (int index = 29; index > -1; index--)
- {
- if ((number1[index] + number2[index] + carryDigit) > 9)
- {
- result[index] = (number1[index] + number2[index] + carryDigit) - 10;
- carryDigit = 1;
- }
- else
- {
- result[index] = number1[index] + number2[index] + carryDigit;
- carryDigit = 0;
- }
- }
- for (int index = 0; index < 30; index++)
- {
- cout << result[index] << ", ";
- }
- */
- ///////////////////////////////////////////////////////////////////
- //Lab9 Part A: anagrams
- /*
- const int wordLength = 50;
- char word1[wordLength];
- char word2[wordLength];
- int count = 0;
- char ch = ' ';
- string line;
- cout << "enter two words" << endl;
- cin >> word1;
- cin >> word2;
- int length;
- length = strlen (word1);
- cout << length;
- for (int index1 = 0; index1 < wordLength; index1++)
- {
- if (strlen (word1) != strlen (word2))
- {
- break;
- }
- for (int index2 = 0; index2 < wordLength; index2++)
- {
- if (word1[index1] == word2[index2])
- {
- count++;
- break;
- }
- }
- }
- if (count == wordLength)
- {
- cout << "Those two words are anagrams!" << endl;
- }
- else
- {
- cout << "Negative. No anagrams found" << endl;
- }
- */
- //sort(lab8, lab8 + 50);
- //for (int count = 0; count < 50; count++)
- // {
- // cout << count << ". " << lab8[count] << endl;
- // }
- ///////////////////////////////////////////////////////////////////
- //Lab9 PartB
- char wordA [9] = {'m','o','n','t','h'};
- char wordB [9] = {'z','o','n'};
- char wordC [9] = {'s','e','a'};
- char wordD [9] = {'s','e','a','l'};
- bool temp;
- //temp = lab9alphabetical (wordA, wordB, 9);
- cout << temp;
- getch();
- return 0;
- }
- void showValues (int numbs[], int size)
- {
- for (int index= 0; index < size; index++)
- {
- cout << numbs[index] << " " ;
- }
- numbs[0] = 200; // array names in functions are like reference variables - changes made to array in a function
- cout << endl << endl <<endl; // are reflected in actual array in calling function.
- }
- void lab8ArrayFiller (int numbers[], int size, int count)
- {
- int digitsRemaining = 30;
- digitsRemaining = digitsRemaining - count;
- while (digitsRemaining != 0)
- {
- for (int index = 28; index > -1; index--)
- {
- numbers[index + 1] = numbers[index];
- }
- numbers[0] = 0;
- digitsRemaining = digitsRemaining - 1;
- }
- }
- void lab9sort (char word1[], char word2[], char word3[], char word4[], int)
- {
- }
- bool lab9alphabetical (char name1[], char name2[], int size)
- {
- for (int index = 0; index < size; index++)
- {
- if (name1[index] < name2[index])
- {
- return true;
- }
- else if (name2[index] < name1[index])
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement