C++ :: Swapping Letters In Array

May 3, 2013

I have a function that is suppose to swap positions of 2 letters but It doesn't seem to work. Im passing in the array of char into the function.

void swapletter(char word[]) {
char temp1;
int swap1;
int swap2;
cout<<"What is the first location: ";
cin>>swap1;

[Code] ....

View 6 Replies


ADVERTISEMENT

C++ :: Swapping Elements In Array?

Nov 25, 2014

I thought I'm done doing mg activity, but my professor said that we need to use a Temporary Variable for Swapping but where to put it.

Here is his activity:

Activity: Swapping Create a program that accepts a 10-element array of type int. Where the 1st user-input is stored in the 1st element of the array; the 2nd user-input is stored in the 2nd element of the array; so on so forth until the last user-input stored in the last element of the array. Your source code should be able to SWAP the values of the 1st and 10th; 2nd and 9th; 3rd and 8th; 4th and 7th; and 5th and 6th elements. It should display the values of the original and the swapped values of the array. example:

Enter 10 integer values:
array[0] = 1
array[1] = 2
array[2] = 3
array[3] = 4

[Code]....

View 1 Replies View Related

C/C++ :: Swapping Elements In A Struct Dynamic Array

Dec 1, 2014

Let's say there is a document which stores data of exams of 3 subject. The document is in the below format:

Subject code [spc] Student code [spc] Exam score [endl]

Repeatedly, there are 100 data. E.g.

ENGL_S12 [spc] 000001 [spc] 90.5
ENGL_S12 [spc] 000005 [spc] 77.3
MATH_G22 [spc] 000502 [spc] 100
LATI_F11 [spc] 002005 [spc] 65.4
...

Now I have to write a function show_exam_descending(Data d, string subCode)
when I call show_exam_descending(d, "ENGL_S12")
the program will execute to show all the students' exam scores in ENGL_S12 in DESCENDING order...

For this to run, I have declared a struct Data:

struct Data {
string subjectCode;
int studentCode;
double examScore;
);

For the search, I have written a function before to load all the data from the document by using pointer and dynamic arrays. It works so well. What troubles me is the way to swap the elements (i.e. examScore) of different students in struct dynamic arrays. I am able to display all of them, but don't know how to swap.

View 8 Replies View Related

C/C++ :: Counting Letters In Char Array

Dec 7, 2014

Assume input is char array holding a C-string. Write code that counts the number of elements in the array that contain an alphabetic character.

counter = 0
for (i = 0; i < SIZE; i++) //size being whatever input's size is
{
if (isalpha(input[i]))
{
counter++;
}
}

Is there anything wrong with this method?

View 8 Replies View Related

C++ :: Count Letters From Text File Into Array?

May 10, 2014

I have to count the letters from a text file into an array so the first spot is the number of A's second spot number of B's and so on then take the array and sort it in decending order how could i do this without loosing track of where the numbers go so if there are more b's than a's they switch but how will i know where each letter has moved in the array after it has been sorted?

View 1 Replies View Related

C :: Converting A String Array Into Uppercase Letters From File

Apr 19, 2013

I am new to coding Here is the problem. Have a program prompt the user for a filename to open. Change every alphabetic character in the file to a capital letter. Numbers and special characters should not be changed. Print the output to the screen.

Here is my code so far but i am only returning the last line of text capitalized from the file. I am trying to get the program to display all of the three lines of text from the file capitalized. The program displays the file correctly before i try and convert everything toupper();

Code:

Code: #include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21];
int i;
FILE *inFile;

[Code]...

View 6 Replies View Related

C :: Strcpy - How To Update Old String In Stars Array With New That Includes Correct Letters

Apr 25, 2013

This for loop replaces the stars ******** in an array that contains a word to be guessed with the correct letter (c) that the user inputs if the word contains that letter.

Problem: After every guess the same hidden string of stars ******* is displayed instead of ex: ***W**** (assuming W was entered by the user)

How can I update the old ******** string in the Stars array with the new string that includes the correct letters chosen, so after every correct guess at a letter in the word a new string is displayed including the correct letters chosen?

I'm pretty sure I have to use strcpy but not sure how to implement it using a loop.

Code:
for(i = 0; i < strlen(unscrambledWord); i++) {
if(unscrambledWord [i] == c) {
Stars[i] = c;
} }

View 1 Replies View Related

C :: Swapping Like Function

Feb 15, 2015

I have a question about one function in my program. Write a function that will replace players in a tim. New player gets in the game, and takes the place of one that leaves. Prototype of function is:

Code:

void replace(TEAM *p,PLAYER newplayer,int num)

where second parameter is new player, and the third is a jersey number of player who leaves the game.Two structures are defined as:

Code:

typedef struct{ char name[25],surname[25];int number;}PLAYER;typedef struct{ char nameofteam[25];int numberofplayers;PLAYER *players;}TEAM;

First I tried to read which player should get out, but that didnt work:

Code:

printf("which player should get out?
"); do { scanf("%s",p->players.number) } while(p->players.number);//

Choose one of previously read players Second thing is to read a new player and replace him with the chosen who leaves.

View 2 Replies View Related

C :: Swapping Some Numbers In String

Jun 15, 2013

I have a pointer to a pointer to a C string:

char**objectData;

In this string there are some numbers with a dash between them, for example, "5-10". I need to read these numbers in and then increment them. So "5-10" becomes "6-11", "6-11" becomes "7-12", etc.

So far I have:

Code: char temp[350]; //350 chars is plenty enough

// Copy the first characters BEFORE the numbers into a new char array. The next characters are the numbers.
strncpy(temp, *objectData, 39); The next steps are:
- Extract the two numbers from the C string (determining if the number is 0,2 or 3 digits long) and write them into two ints. I'm stuck here.

- Increment the ints

- Write the ints into the array with a dash inbetween.

View 6 Replies View Related

C/C++ :: Access The Swapping Function?

Nov 22, 2014

Giving the following program, how do i access the swapping function. I've tried swapp::change <int> ( a, b ) ; and it gave me 4 errors. Here's the code:

#include <iostream>
using namespace std;
template <typename T>
class swapp

[Code].....

View 5 Replies View Related

C :: Swapping Structures Inside File

Apr 9, 2013

I tried normal swapping method like this (counter is number of structures written in file) :

Code:
fopen("books.txt","r+");
system ("cls");
for(i=1;i<counter-1;i++){
for(j=1+1;j<counter;j++){
fscanf(f," %[^,], %[^,], %[^,],

[Code] ....

But it doesn't do anything.

View 2 Replies View Related

C# :: Swapping Multi Usercontrol In 1 Winform?

Jul 29, 2014

So basically, I started out with each wizard == 1 winform, but then I found another way to do it by making the content of each wizard step a user control, then say, on initial deployment, it load usercontrol1, then when i click next, the panel hide usercontrol1 for usercontrol2 and so forth. Would it be feasible to create all usercontrols (all the wizard step) and add them in an array, then i can load them by index?

View 7 Replies View Related

C/C++ :: Swapping Of Position Of Elements In A Sequence

Oct 24, 2013

Write a program that gets a sequence of unsigned integers.the user can enter at most 100 integers.

After getting the numbers, the program allows the user to repeatedly choose one of the three options:

1. swap the location of two entries in the sequence. if this option is chosen the user is prompted to enter the two locations to be swapped.

2. print out the sequence.

3. repeatedly swap two locations in the sequence until getting back to the state before this operation started. then print out the number of swaps performed.

View 3 Replies View Related

C++ :: Swapping Two Adjacent Linked Lists Nodes

Oct 22, 2014

I am working on a program where I sort elements into alphabetical order and then when one is less than the other I swap them. I first did it by swapping the data but they want me to swap the nodes instead and I am having trouble doing that.

Node *add_node( Node *list, const string &s ) {
struct Node *n = new struct Node;
n->word = s; // copy string s to word
n->next = 0;

// add node n to the list
// the list should always be in ascending alphabetical order
n->next = list;
list = n;

[Code] ....

View 2 Replies View Related

C++ :: Swapping Nodes In Doubly Linked List?

Nov 15, 2014

I've been working on this linked list priority queue . I know that the root of the problem is in my swapUp() function (swapping the positioning of two nodes based on their priority), because the list works great up until it is called. The seg fault is not actually being caused by swapUp(), it's being caused by peekAt(), which returns the element in the node at position n. But the error does not occur unless swapUp() is called first, so that is where the issue is (I think).

There is also a seg fault being caused in the destructor, which I believe may have the same root cause in swapUp().

PRIORITY QUEUE:

#ifndef JMF_PriorityQueue
#define JMF_PriorityQueue
#include <iostream>
#include <string>
template <typename T>
class PriorityQueue{

[Code] .....

Okay, so I've tried implementing SwapUp() in a different new way, but it's still giving me the same problem

template <typename T>
void PriorityQueue<T>::swapUp(Node * target){
Node * partner = target->next; //Partner = target next

[Code] .....

This is such an elementary logic problem I don't know why I'm having so much trouble with it.

View 4 Replies View Related

C/C++ :: Swapping Like Function - Replace Player In A Team

Feb 14, 2015

I have a question about one function in my program. Write a function that will replace players in a team. New player gets in the game, and takes the place of one that leaves. Prototype of function is:

void replace(TEAM *p,PLAYER newplayer,int num)

where second parameter is new player, and the third is a jersey number of player who leaves the game.
Two structures are defined as:

typedef struct {
char name[25],surname[25];int number;
}PLAYER;
typedef struct {
char nameofteam[25];int numberofplayers;PLAYER *players;
}TEAM;

First I tried to read which player should get out, but that didnt work:

printf("which player should get out?");
do {
scanf("%s",p->players.number)
} while(p->players.number);//Choose one of previously read players

Second thing is to read a new player and replace him with the chosen who leaves.

View 3 Replies View Related

C++ :: User Defined Function - String Related Program (swapping)

Jan 4, 2015

Write a program using user-defined function which is passed a string and that function should cycle the string.(Do not use any string related functions). E.g.

If the string is : Chetna then it should print as Chetna, hetnaC, etnaCh, tnaChe,naChet, aChetn

Ans.

#include <iostream>
using namespace std;
char swamp(char a[], int x) {
for(int k=0; k<=x; k++) {
char l= a[x]; a[x]= a[0]; char p=a[x-1]; a[x-1]=l;
for(int i=1; i<x-2; i++) {

[Code]...

View 19 Replies View Related

C/C++ :: Swapping Vector Int And Vector Strings

Mar 30, 2013

I want to have it so that when i ask for the person witch item they want to drop on the ground it goes into another vector that i can pick back up the item if they want it back and erase when they walk away.

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>  
using namespace std;  
    struct InventoryItem

[Code] ....

View 4 Replies View Related

C++ :: How To Count Letters

Mar 16, 2013

I'm just trying to find out if the way I've setup my code currently allows me to count the letters as they occur? I don't yet see how to do it but I need clarification. Ideally the function letterCounter would do the counting but atm I'm just trying to figuring it out in the display function.

View 2 Replies View Related

C :: Writing Numbers In Letters?

Jan 26, 2013

Code:
#include<stdio.h>
#include<string.h>
#define a 9
#define b 9
#define c 3
int main() {

[Code] .....

In practice section there was a challenge to print up numbers in letters up to billion including negatives I didn't look at the solution and came up with this but it is getting difficult after this point....

View 9 Replies View Related

C :: Printing A Parallelogram From Letters

Nov 14, 2013

These are the instructions: read a number between 1-26 and build a parallelogram in the size (height&width) of the number entered.

Each row of the parallelogram will be built from each capital letter from 1 to the number read (max 26).for example: by entering the number 3, will be printed:

AAA
_BBB
__CCC

for the number 4:
AAAA
_BBBB
__CCCC
___DDDD

I am struggling with how to change each char in every different row, how do I print this parallelogram ?

View 8 Replies View Related

C :: Converting Letters To Hexadecimal

Jun 3, 2014

i m trying to write a code that would convert a each letter from a text to their decimal images . while i was able to write the part of entering the text , i cant do the converting part , i searched all day on the internet and found nothing.

View 3 Replies View Related

C++ :: How To Read Selected Letters

Jun 1, 2013

I have a text file in which i need to read only selected letters and substitute them with integers to calculate.

Eg:-
In the text file
f2,h1

Here i need to read only the the letters f & h and substitute them with some integer and add them up.

View 1 Replies View Related

C++ :: A Program To Print Big Letters?

Nov 28, 2013

I need help writing a program where I use small letter to write names in Big letters. (I dont know if you understand what i mean). Follow link to description.

[URL]

View 6 Replies View Related

C++ :: How To Put 2 Letters Together And Make Them To Count As 1

Mar 11, 2013

how to put 2 letters together and make them to count as 1?

provided that they must consecutive

for example:

p : count as 0
pxp : count as 0
pp : count as 1
xpxp: count as 0
ppxpp : count as 2

View 1 Replies View Related

C++ :: Capital And Lowercase Letters?

Sep 26, 2013

I am writing a code that requires the user to input either B or b for bright or D or d for dim. Basically, B is bright and D is dim but I have to code the program such that it allows for both he capital letter and the lowercase letter to be recognized.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved