write c++ code that has a function int GreaterThan (int array [], int size, int searchItem). The fucntion should count and return number of elements in the array greater than SearchItem. you are free to generate the element randomly or let the user enter them, the size must be less than ten

The logic is given, now do this in code. I'm pretty sure you can do this yourself first. If you get stuck and need help you can surely come here and post your code.

Read an array of integers of 20 values
then do the following processes :
1- delete all prime and all even numbers from the array and store them in a new array then display the values of the new array on screen.
2- after you delete all prime and all even numbers from the original array display the odd numbers of the array in descending order on screen.
3- display on screen the square root of the prime numbers stored in the new array

What do you need help with? What code do you have so far? If "help me please" is slang for "give me code" then you will find no one is going to "help" you.

Edited 3 Years Ago by NathanOliver

#include<iostream>      //All rights reserved :p//
#include<cstdlib>         //programmer's Name:Syed Dawood //
using namespace std;       // NIck: UFOOOOOOOOOOO//

 int size=0;   //size of array//
int GreaterThan (int array [],int search_item);   //your funtion's protoype//

void main()
{
    int search_item=0;   //your search item//
    int count=0;     //will hold final result//

    cout<<"Please enter thr size of array\n";       //user input of size//
    cin>>size;

    int *arr=new int[size];     //creating array//
    for(int i=0;i<size;i++)     
    {
        cout<<"enter your element\n";     //taking userinput of elements//
        cin>>arr[i];
    }
    cout<<"Enter your search item\n";
    cin>>search_item;
    count=GreaterThan(arr,search_item);    //function call//

    cout<<"Total number of elements greater than your search item are "<<count<<endl;   //final result//


}

int GreaterThan (int arr [],int search_item)
{
    int count=0;
    for(int i=0;i<size;i++)    //counting number of elements grater than search item//
    {
        if(arr[i]>search_item)
        {
            count++;
        }
    }

    return count;
}
Comments
Why would you just give him a solution?

Well programming is fun for me so if i am providing a solution no one should ask me that why should i provide solution?its my choice providing solution or not...haters keep on hating

Edited 3 Years Ago by UFOOOOOOOOOOO

You're spoonfeeding the answer to what is clearly a homework assignment to somebody who doesn't want to do any of the programming themselves. This is the reason so many people can get CS degrees without even knowing how to do FizzBuzz. I hope his professor is at least smart enough to mark him down for void main() when he turns this one in.

That's a great attitude to have. To have main() return an int is in the standard for a reason. Some systems need that value returned from main() for them to function correctly. Some compilers will not even compile your code because of it. Just because you use it and you haven't had a problem does not mean it will work everywhere.

your code is even more error prone. memory leaks.
new allocation always need to be freed.
On line 16. for something simple like this, there was no need using new alloc. just simple

const int foo=10;
int afoo[foo];

something more simpler and effective for basic data ops. The point is you are allowed to do as you please but clean our mess after.

Just a cup of coffee advice.

I know that I worked (and still do) very hard to learn how to code a program from requirements and I feel like some of the other posters above that people who REFUSE to even try to learn to write a simple program shouldn't be getting any kind of programming degree. The FizzBuzz comment was especially valid. What is the requirements of the program? You have to fill an array and then search that array for the number of elements greater than a search value...seriously, put the pencil to the paper or the fingers to the keys and think about what needs to be coded and write some code and then post it here and maybe you can get some help. Show that you want to learn and people will be MUCH more willing to help you.

Write a C++ program that reads text from a notepad, and then count how many times each word appears. The results must be shown on another file in a tabular form. The name of this output file will be provided by the user during program execution.

Platinum Beauty Saloon provides services and sells beauty products. It offers 3 types of memberships: Premium, Gold and Silver. Premium, gold and silver members receive a discount of 20%, 15%, and 10%, respectively, for all services provided. Customers without membership receive no discount. All members receives a flat 10% discount on products purchased (this might change in future). You are required to build a Discount System which shall consist of three structures: Customer, Discount and Visit. It shall compute the total bill if a customer purchases x-amount of products and y-amount of services, for a visit. Also, write a main function to exercise all the classes.

A stack is a data type which follows Last-In-First-Out rule. This means that an element that was the last one to be inserted inside the list will be the first one to be taken out. On the basis of this information, write a complete program using a structure to model this data type.

A stack is a data type which follows Last-In-First-Out rule. This means that an element that was the last one to be inserted inside the list will be the first one to be taken out. On the basis of this information, write a complete program using a structure to model this data type. The struct interface is as follows:
struct Stack
no
int top; // A variable that shows how many elements are in the array
Stack(); // Constructor
bool Push( int x); // A function that inserts an element into the stack
bool Pop(); // A function that deletes an element from the stack
bool IsEmpty(); // A function that determines if the stack is empty
bool IsFull(); // A function that determines if the stack is full
void Print(); // A function that prints all the elements in the stack

OK, here's a question for you: why are you posting all this here when it has nothing to do with the (already answered) original question?

Edited 3 Years Ago by happygeek

This question has already been answered. Start a new discussion instead.