isralruval 0 Newbie Poster

i have the following function which works, its encrypts a text file, well its suppose to shift the letters of a text file by whatever the user wants, lets say the text file says "zoo" if the user wants to shift the letters by 1 to the right the output of it should say "app"
but lets say i want to shift it 13 to the right, it wont give the correct results
instead of giving me "mbb" it gives me something random it outputs "\207bb"
anyone wants to help me fix it??

void rotateEncrypt(vector<string> V1, vector<string> V2, int rotKey)
{
char ch;
int k;
string word = V1[0];
for (unsigned i=0; i<word.size();i++)
{
if(word[i]!=' '){
ch = tolower( word[i]);
ch = ch + rotKey;
if(ch > 'z')ch = 'a' + (ch - 'z' -1);
word[i] = ch;
}
}
V2.push_back(word);
ofstream fo("simpler.txt" ,ios::app);
fo<< word <<'\n';
fo.clear();
fo.close();
}
isralruval 0 Newbie Poster

i have the following function which works, its encrypts a text file, well its suppose to shift the letters of a text file by whatever the user wants, lets say the text file says "zoo" if the user wants to shift the letters by 1 to the right the output of it should say "app"
but lets say i want to shift it 13 to the right, it wont give the correct results
instead of giving me "mbb" it gives me something random it outputs "\207bb"
anyone wants to help me fix it??

void rotateEncrypt(vector<string> V1, vector<string> V2, int rotKey)
{
char ch;
int k;
string word = V1[0];
for (unsigned i=0; i<word.size();i++)
{
if(word[i]!=' '){
ch = tolower( word[i]);
ch = ch + rotKey;
if(ch > 'z')ch = 'a' + (ch - 'z' -1);
word[i] = ch;
}
}
V2.push_back(word);
ofstream fo("simpler.txt" ,ios::app);
fo<< word <<'\n';
fo.clear();
fo.close();
}
isralruval 0 Newbie Poster

i have the following code which works, well its suppose to shift the letters of a text file by whatever the user wants, lets say the text file says "hi" if the user wants to shift the letters by 1 to the right it will become "ij"
ok but the problem is when i want to shift a letter that goes over the alphabet, like lets say the word is "zoo" if i want to shift it by one the letter z will give me a random character that i dont want, the whole word should become "app"
anybody wants to help me fix this??

void rotateEncrypt(vector<string> V1, vector<string> V2, int rotKey)
{

  char ch;
  int k;
  string word = V1[0];
  for (unsigned i=0; i<word.size();i++)
    {
      if(word[i]!=' ')
        {
          ch = tolower( word[i]);
          ch = ch + rotKey;
          word[i] = ch;
          if(ch > 'z');
          k = ch -'z';
          ch = 'a'+k - 1;
          word[i] = ch;
        }
    }
  V2.push_back(word);
  ofstream fo("simpler.txt" ,ios::app);
  fo<< word <<'\n';
  fo.clear();
  fo.close();
}
isralruval 0 Newbie Poster

yes it turns into that and yes its suppose to add one to each letter , well actually add whatever the user wants to add . thats why the rotKey is there.

isralruval 0 Newbie Poster

i know the following function is not correct, but its suppose to read a text file(which containts the words "hello all") and pass it to a Vector
called V1 and then encrypt it and pass the encryption to a second vector called V2 and finally output the result into a different text file.that text file should be "ifllp bmm" , which means that the file is being encrypted using ciphers method. Can anyone help me fix it??

void rotate(vector<string> V1, vector<string> V2, int rotKey)

{
string original;
ifstream fin;
fin.open("simple.txt");
string word = V1[0];
word[0];
for (int i = 0; i < V1.size(); i++)
{
char ch = word[i];
ch = tolower(ch);
ch = ch + rotKey;// lets say i want to shift the letter by one to the right
if(ch > 'z')
{
int k = ch -'z';
ch = 'a'+'k' - 1;
}
word[i] = ch;
V2.push_back(word);
}
}
isralruval 0 Newbie Poster

im having trouble with my program. it reads the student id, and both grades from a file and then a function its suppose to calculate the average of both grades and then pass the results to the main program using pass by reference. And for some reason my average its way off.
if anyone can help me out

currently my output looks like this:
Std-Id S1 S2 AVERAGE
-----------------------------------------------
126534 9 84.86621e-270
321345 7 34.86621e-270
324341 9 94.86621e-270
324341 9 94.86621e-270

this is what the output suppose to look like:

Std-Id S1 S2 AVERAGE
-----------------------------------------------
126534 9 8 8.5
321345 7 3 5.0
324341 9 9 9.0

#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;

double oneLine(double S1, double S2, double &avg);

int main()
{
  cout << "Std-Id" << setw(9) << "S1" << setw(6) << "S2" << setw(6)
       <<  "    AVERAGE" << endl;
  cout << "-----------------------------------------------" << endl;

  ifstream input("data4.txt");

  double student;
  double S1, S2;
  double avg;
  int line;

  if(!input)
    cout << "The input file doesn't exist" << endl;
  else
    while(!input.eof())
      {
        input >> student >> S1>> S2;
        oneLine(S1, S2, avg);
        cout << student << setw(9) << S1 << setw(6) << S2
             << setw(6) << avg << endl;

        line ++;
      }
  input.close();

  return 0;
}

double oneLine(double S1, double S2, double &avg)
  {
    double sum;
    double  result;
    sum = (S1 + S2)/2;
    return sum;
  }
isralruval 0 Newbie Poster

This code you are asked to input a number and it will tell u wheter or not the input you entered is in the array or not
i am having issues with this code and its giving me some errors,
if anyone wants to help me out it will be greatly appreciated!

include <iostream>
using namespace std;

int search(int a[], int size, int searchKey);

int main()
{
  int small, a[]= {10, 15, 27, 89, 90, 95, 27, 13, 99, 33};
  const int size = 10;
  int i;
  int target;
  int searchKey;

  cout << "Enter a number to be found: ";
  cin >> target;

  if(a[i] == target)
    cout <<"Number found" ;
  else
    cout <<"Number not found in the array" << endl;

  return 0;

  int search(int a[], int size, int searchKey)
  {
    {
      int i;
      int target;
      for(a[i] = 0; i < size; i++)
        {
          if(a[i] == target)
            return i;
        }
          else return 0;
    }
  }
isralruval 0 Newbie Poster

ok, so i have a simple code below but i need an array function that calculates which elements are divisible by 5 and then its passes the results to the main function and outputs them, any help with code on how to do it will be appreciated?
basically the above code and the one i want do the same thing. but i need help on this one.
the array function should look something like this: calcdiv(int[a], int size];
thanks in advance

#include <iostream>

using namespace std;

int main() {
  int a[5] = {5, 10, 13, 20 , 39};
  int result[5] = {-1, -1, -1, -1, -1};
  int count = 0;

  for(int i = 0; i < 5; i++) {
    if((a[i] % 5) == 0) {
      result[count] = a[i];
      count++;
    }
  }

  for(int i = 0; result[i] != -1 && i < 5; i++) {
    cout << result[i] << ' ';
  }

  return 0;
}
isralruval 0 Newbie Poster

im having a difficult time figuring out my last two functions.

first one which is the
int divelement(int a[], int size);
this function is suppose to find and print the elements of my array that are only divisible by 5, so the answer will be like 10,15,90, and 95. i need help figuring out the algorithm

for my second one
int search(int a[], int size);
the user enters a number, and if the number is in the array it outputs "the number you enter does exist" and if it doesnt it outputs "the number you enter does not exist"

any help will be appreciated. or at least anyway how to get this started. thanks

#include <iostream>
#include <cmath>
using namespace std;

void printArray(int a[], int size);
void reverse(int a[], int size);
int average(int a[], int size);
int min( int a[], int size);
int divelement(int a[], int size);
int search(int a[], int size);

int main()
{
  const int size = 10;
  int small,a[] = {10, 15, 27, 89, 90, 95, 27, 13, 99, 33};
  small = a[0];
  int number;

  cout << "The original array is: ";
  printArray(a,10);
  cout << endl;

  reverse(a,size);
  cout << "The reversed array is: ";
  printArray(a,size);
  cout << endl;

  cout << "The average of the array is: "
       << average(a, size) << endl;

  min(a, size);
    cout << "The smallest element in the array is: "
         << small << endl;

    cout << "Enter a number between 1 and 99: " << …
isralruval 0 Newbie Poster

File Edit Options Buffers Tools C++ Help

#include <iostream>
#include <cmath>
using namespace std;

void printArray(const int a[], int size);
void reverse(const int a[], int aReverse[], int size);
int average(const int a[], int size);


int main()
{
  int size = 10;
  int a[] = {10, 15, 27, 89, 90, 95, 27, 13, 99, 33};
  int aReverse;

  cout << "The original array: ";
  printArray(a,10);
  cout << endl;

  reverse(a, aReverse, size);
  cout << "The reversed array is: ";
  printArray(aReverse,10);
  cout << endl;

  cout << "The average of the array is: "
       << average(a, 10) << endl;


  return 0;
}

void printArray(const int a[], int size)
{
  for (int i = 0; i < size; i++)
    cout << a[i] << " ";
}
void reverse(const int a[], int aReverse[], int size)
{
  for(int i = 0, j = size - 1; i < size; i++, j--)
    {
      aReverse[j] = a[i];
  }
}

int average(const int a[], int size)
{
  int sum = 0;
  for (int i = 0; i < size; i++)
    sum += a[i];
  return sum / size;
}
isralruval 0 Newbie Poster

how would i write a function that parses a hex number as a string into a decimal integer. I have the following done i just need help finishing it. any help will be appreciated

#include <iostream>
#include <string>
using namespace std;

int parseHex(const string &hexString)

int main()
{
  cout << "Enter a hex number: ";
  string hexString;
  cin >> hexString;
  cout <<"The number in decimal is"
       << parseHex(hexString) << endl;

  return 0;
}

int parseHex(const string &hexString)
{
  int value = hexString[0]
isralruval 0 Newbie Poster

how would i write a function that parses a hex number as a string into a decimal integer?
the following header should be:
int parseHex(const string &hexString)

isralruval 0 Newbie Poster

its actually line 47 here, not line 51

isralruval 0 Newbie Poster

when i compile i get an error message saying the following
"51: error: assignment of read-only location"
line 51 reads: c[j] = a[j] + b[j];
any help to get rid of this problem???

#include <iostream>
#include <iomanip>
using namespace std;

#define N 3
void addMatrix(const double a[][N],
               const double b[][N], const double c[][N]);
int main()
{
  double a[N][N];
  double b[N][N];
  double c[N][N];

  // Enter nine digits for matrix 1                                                                              
  cout << "Enter matrix1: ";

  for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      cin >> a[i][j];
    }
  // Enter nine digits for matrix 2                                                                              
  cout << "Enter matrix2: ";

  for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      cin >> b[i][j];
    }

  for(int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      c[i][j] = 0;
    }
  addMatrix(a,b,c);

  return 0;
}

void addMatrix(const double a[][N],
               const double b[][N], const double c[][N])
{
  for (int i = 0; i < N; i++)
    {
     for (int j = 0; j < N; j++)
        c[i][j] = a[i][j] + b[i][j];
    }
 cout << " The multiplication of the matrices is " << endl;

 for (int i = 0; i < N; i++)
   {

 for (int j = 0; j < N; j++)
   cout << a[i][j];

 if(i == 0)
   cout << setw(3);
   else if(i == 1)
     cout << setw(3) <<"+" << setw(3);
   else …