geryin 0 Newbie Poster

This was part of a questionnaire.

I have no idea what they are asking... my closest guess is

float rational

please help! thank you.

geryin 0 Newbie Poster

Write a program which initializes two vectors, one of type integer, the other of string. Populate the string type vector with five strings (‘one’, ‘two’, ... ‘five’). Populate the integer vector with [ 5 4 3 2 1 1 2 3 4 5 ]. Write a function that empties the integer vector while printing the string equivalent of each number in the vector. Use the integers as indexes for the string vector you created in order to accomplish this task.

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
    vector<int> intVector;

    intVector.push_back(5);
    intVector.push_back(4);
    intVector.push_back(3);
    intVector.push_back(2);
	intVector.push_back(1);
	intVector.push_back(1);
	intVector.push_back(2);
	intVector.push_back(3);
	intVector.push_back(4);
	intVector.push_back(5);

	cout << "Integers: " << endl;
    for(unsigned int i=0; i < intVector.size(); i++) 
    cout << intVector[i] << " ";
    cout << "\n" << endl;

	vector<string> strVector;

	strVector.push_back("one");
	strVector.push_back("two");
	strVector.push_back("three");
	strVector.push_back("four");
	strVector.push_back("five");

	cout << "Strings: " << endl;
	for(unsigned int i=0; i < strVector.size(); i++) 
    cout << strVector[i] << " ";
    cout << "\n" << endl;


  for(unsigned int i=0; i < intVector.size(); i++) 
  {
      intVector.erase( intVector.begin() );
	  cout << strVector[i] << " ";
  }

  cout << "\n" << endl;
  
  return 1;
}

my code wont print pass the first 5, but it ignore the 5 4 3 2 1.... please help!

geryin 0 Newbie Poster

Write exactly four lines of code which declare one vector and one string (of any size and value you choose) and print their size to the console using a call to a member function of each variable’s respective class.

I would write a sample but I dont really have much else:

#include <iostream>
 #include <string>
  
  using namespace std;
  
  int main(void)
  {
    string word = ;
     vector<int> Vector

thank you

geryin 0 Newbie Poster

Write a function that accepts an array of integers and determines the difference between the integers. For example, if the array [3 7 8 13 11] is passed to the function, it prints to the screen [3 4 1 5 -2].

mine give me : 3, 4 ,4 9, 2
but i cant see why its wrong! please help

#include <iostream>
using namespace std;

#define n 5

void ArraySub(double* MainArray)
{
	int i;

	for (i=1; i<n; i++)
	{
		MainArray[i] = MainArray[i] - MainArray[i-1];
	}
}

int main(void)
{
	double Array[n] = { 3, 10, 243, 8374, 102893};

	ArraySub(Array);

	for (int i=0; i<n; i++)
	{
		cout << Array[i] << endl;
	}

	return 1;
}
geryin 0 Newbie Poster

Write a function to compute the value of the following series.
f(x, y) = y( ((1/1) - (1/3)) + ((1/5) - (1/7)) + ((1/9) - (1/11)) ... + (1/(4x-3) - 1/(4x-1)) )


where the values x and y are given by the user. The main function should continue to query the user for values of x and y until the x is entered as a zero. For example, if x=3 and y=2, the series is:
f(3, 2) = 2*( ((1/1) - (1/3)) + ((1/5) - (1/7)) + ((1/(4*3-3) - (1/(4*3-1))
f(3, 2) = 2*( ((1/1) - (1/3)) + ((1/5) - (1/7)) + ((1/9) - (1/11))
f(3, 2) = 2*( 0.6667 + .0571 + .0202 )
f(3, 2) = 1.48802

geryin 0 Newbie Poster

i am not really good with arrays, also when I do the multiplication it does not give me back in array form

geryin 0 Newbie Poster

I need to find 3*7, 7*8, 8*2, etc..

geryin 0 Newbie Poster

Write a function that accepts an array of integers and determines the product of each two integers. Although you can create a fixed size array in main, your function should work no matter what size of array is passed to the function.

MY code:

#include <iostream>
using namespace std;

void Product(float matrix[4][4], int rows, int columns)
{
int iRow, iColumn, ia, ib;
for(iRow = 0; iRow < rows; iRow++)
for(iColumn = 0; iColumn < columns; iColumn++)
{
for(ia = iRow; ia < rows; ia++)
for(ib = iColumn + !!(ia == iRow); ib < columns; ib++)
cout << ("\t ", matrix[iRow][iColumn] * matrix[ia][ib]) << endl;
cout << ("");
}
}

My code was incorrect and my teacher gave me this note:

If the array [3 7 8 2 -3] is passed to the function, it prints to the screen [3 21 56 16 -6]. (note the first element of the array is not modified) Pass the array to the function and then print the resulting array to the console. (you do not need to store the result in a new array)

please help me fix my function! thank you.

geryin 0 Newbie Poster
#include <cmath>
#include <iostream>
using namespace std;

void prime(int num)
{
int numPrime=true;
for(int c=2;c<num;c++)
{
if (num % c == 0) 
{
numPrime=false;
break;
}
}
if (numPrime == true) 
cout << "TRUE" << endl;
  else
cout << "FALSE" << endl;
}

int main ()
{
int n;
int x = 1;
while ( x != 0 )
{
cout << "Enter a number or 0 to exit ";
cin >> n;
if ( n != 0 )
prime(n);
if (n == 0 )
	break;
}
return 0;
}

Write a function that takes one integer as an argument and determines if the value is prime or not. If it is prime, return true. If not return false. Your main function should query the user for integers and use the function to determine if it is true or false and print the result to the screen. The program should continue to work until the user enters a query for zero. At that time, the program should let the user know both how many numbers where checked and the total number of prime numbers found.

I do not know how to add the checker at the end, please help!