Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Friday, December 14, 2018

Sum of Digits in a String

Write a program that by command of button click read from a file a big integer number.
The program should display this number and the sum of all the single digits of the inputted number.
For example, if the program reads the integer number 2514, the program should display 2514 in the one text-box and 12 in another text-box, which is the sum: 2+5+1+4 = 12.
The program should also display the highest and lowest single digits of the integer number in the two more text boxes.
For the example number 2514, these single digits are 5 and 1.

Friday, November 9, 2018

This program uses the bubble sort algorithm to sort an string array in alphabet order

// This program have been developed by changing program Pr8-4
// Array of integer numbers have been changed to array of strings.
#include "stdafx.h"
#include <string>       // Add this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Pr8-4 for strings
// This program uses the bubble sort algorithm to sort an
// string array in alphabet order.
#include <iostream>
using namespace std;

// Function prototypes
void sortArray(string [], int);
void showArray(string [], int);

int main()
{
// Array of unsorted strings.
string values[6] = {"Hussein","Zachary" ,"Diarra", "Chris", "Delong", "Kenneth"};

// Display the strings.
cout << "The unsorted values are:\n";
showArray(values, 6);

// Sort the strings.
sortArray(values, 6);

// Display them again.
cout << "The sorted values are:\n";
showArray(values, 6);
return 0;
}

//***********************************************************
// Definition of function sortArray *
// This function performs an ascending order bubble sort on *
// array. size is the number of elements in the array. *
//***********************************************************

void sortArray(string array[], int size)
{
bool swap;
string temp;

do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}
} while (swap);
}

//*************************************************************
// Definition of function showArray. *
// This function displays the contents of array. size is the *
// number of elements. *
//*************************************************************

void showArray( string array[], int size)
{
for (int count = 0; count < size; count++)
cout << array[count] << "\n";
cout << endl;
}

Basic Comparison of C++ and HTML/JavaScript

 Here’s a basic comparison of C++ and HTML/JavaScript for common programming concepts and  simple code examples for each. This will help ...