Dont understand coding project need guidance

So I just received my new coding assignment and I have no idea how to even start it. The instructions are so long that I just copy and pasted the link.

http://www.husaingholoom.com/files/1428/C++ProgramAssignment-6.pdf

I dont expect anyone to just do it for me but any help at all would be greatly appreciated.
Here is what I have done so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

using namespace std;

int main()
{
    int input;          // This will be the number the user enters for size of array

    cout << "This is an array manipulation program" << endl;
    cout << "\nEnter the size of the array ";
    cin  >> input;
    cout << "Enter any " << input << " Characters, Digits, or Special Symbols   :  " << endl;
    int num[input];

    return 0;
}
Allow the user to populate an array using N characters from the keyboard.
Display the entire array.
Display all capital letters or none in the array.
Display all small letters or none in the array.
Display all digits or none in the array.
Display all special symbols or none in the array.
Reverse the order of the element of the array then display the array.
Convert all small letters to capital letters and vice-versa, then display the array
Rotate all the elements to the array to the left 2 positions.

Man, if you find that long, I'm gonna pray for you when you run into a 100,000 element vector...


Okay, step one.
Allow the user to populate an array using N characters from the keyboard.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main()
{
    int input;          // This will be the number the user enters for size of array

    cout << "This is an array manipulation program" << endl;
    cout << "\nEnter the size of the array ";
    cin  >> input;
    
    cout << "Enter any " << input << " Characters, Digits, or Special Symbols   :  " << endl;
    
//  How do we ask for multiple inputs? How are you going to control the number of times
//  a user can input a Characters, Digits, or Special Symbols?




    return 0;
}
 

Last edited on
sorry haha i am in a beginner class in college. Could I get multiple inputs from something like a for loop? i know i could get multiple inputs from manually declaring variables. lastly I believe i could control the number of times with a loop maybe?
the size of an array cannot be non constant int num[input];
you didnt understand the question in pdf


Could I get multiple inputs from something like a for loop?

yes. loop at the count of the index of the array
Last edited on
1st task is pretty straightforward

1
2
3
4
5
6
7
8
9
10
11
12
13

unsigned int N;
std::cin>>N;

char * array;
array=new char[N];

for(int i=0; i<=N; ++i)
{
   std::cout<<"\nInsert element :";
   std::cin>>array[i];
}



2nd one too

1
2
3
4
5
for(int i=0; i<=N; ++i)
{
   std::cout<<array[i]<<'\n';
}


2nd one too

1
2
3
4
5
for(int i=0; i<=N; ++i)
{
   std::cout<<array[i];
}


3rd one may be trickier for a beginner, but it's not hard at all

1
2
3
4
5
6
7
8
9
10
11
12
13

bool CapitalExists=false;

for(int i=0; i<=N; ++i)
{
   if(array[i]=>'A' && array[i]>='Z') 
     {  CapitalExists=true;
         std::cout<<array[i];
     }
}

if(!CapitalExists) 
  std::cout<<"There are no capital numbers in the array \n";


4th, 5th, 6th. 6th is a little bit different but the same principle applies

7th, just use an auxiliary array (as you still need the original)

1
2
3
4
5
6
7
8
9

char * auxiliary=new char[N];

for(int i=0; i<N;++i)
{
    auxiliary[i]=array[N-i];
    std::cout<<auxiliary[i];
}


8th , there's a difference of 32 between a small letter and its capital
1
2
3
4
5
for(int i=0; i<N;++i)
{
    if(array[i]>='A' && array[i]<='Z') std::cout<<char(array[i]+=32);
    else if(array[i]>='a' && array[i]<='z') std::cout<<char(array[i]-=32);
}





Last edited on

Don't apologize for being in a beginner class in college... We all start in the same place, a desire to know more... You have to begin somewhere.
Yes! A loop is an excellent choice... So, we have that figured out.

Okay... lets figure out what we're going to do for step 2.
Display the entire array.

How will we do that? Another loop? Perfect... We know how we're going to do that.

Now, on to step 3. Let's figure that out...
Display all capital letters or none in the array.

Okay, this ones a little tougher... Again we can jump to our friend the loop for a solution.
This time, instead of a simple print, or input... you get to show off your talent. As you traverse through this array, you only need to concern yourself with uppercase letters.
For that, we use the American Standard Code for Information Interchange (Ascii for short)
Each symbol, number, upper and lower case letter, and so on are represented by a number.
That's a good t hing to know in this case. You can see the table here:
http://www.ascii-code.com/ Now in this section, you may want to use your knowledge of ascii tables, IF statements, perhaps the else command and loops.
This should carry you all the way to converting upper to lower and viceversa...


so far this is how far ive gotten. Just a disclaimer I am only allowed to use the iostream library. I have come into some problems that I do not know how to fix. Firstly When I enter my number into the array it always goes one more. So for example if i enter 5 i have to enter 6 numbers. Secondly the prof wants it so that When it says what the array contains it will be like 12345 not 1 2 3 4 5. And lastly I get an error that a primary expression is needed for the if statements in the bool loop. I am progressing slowly and I know i still have a ways to go but any help is greatly appreciated.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>

using namespace std;

int main()
{
    int N;          // This will be the number the user enters for size of array
    cout << "This is an array manipulation program" << endl;
    cout << "\nEnter the size of the array ";
    cin  >> N;
    char * array;
    array = new char[N];

    cout << "\nEnter any " << N << " Characters, Digits, or Special Symbols : ";
    for(int i=0; i<=N; ++i)
    {
    cin>>array[i];
    }
    cout << "\n\nThe array contains the following   :   " << endl;

    for(int i=0; i<=N; ++i)
    {
        cout<<array[i]<<' ';
    }


    bool CapitalExists=false;

    for(int i=0; i<=N; ++i)
    {
       if (array[i]=> 'A' && array[i]>= 'Z')
         {  CapitalExists=true;
             cout<<array[i];
         }
    if(!CapitalExists)
      cout<<"There are no capital letters in the array \n";

    bool lowerExists=false;

    for(int i=0; i<=N; ++i)
    {
       if(array[i]=>'a' && array[i]>='z')
         {  lowerExists=true;
             cout<<array[i];
         }

    if(!lowerExists)
      cout<<"There are no lowercase letters in the array \n";


    return 0;
}

you forgot a '}' for both loops, just before checking if(!CapitalExists) and if(!lowerExists). If you want 12345 instead of 1 2 3 4 5, just delete the <<' ' after array[i]. Also it needs to be smaller than 'Z' and 'z', not bigger, you used > instead of <
Last edited on
Hi I am still getting the expected primary expression before the > on lines 31 and 43


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>

using namespace std;

int main()
{
    int N;          // This will be the number the user enters for size of array
    cout << "This is an array manipulation program" << endl;
    cout << "\nEnter the size of the array ";
    cin  >> N;
    char * array;
    array = new char[N];

    cout << "\nEnter any " << N << " Characters, Digits, or Special Symbols : ";
    for(int i=0; i<=N; ++i)
    {
    cin>>array[i];
    }
    cout << "\n\nThe array contains the following   :   " << endl;

    for(int i=0; i<=N; ++i)
    {
        cout<<array[i];
    }


    bool CapitalExists=false;

    for(int i=0; i<=N; ++i)
    {
       if (array[i]=> 'A' && array[i]<= 'Z')
         {  CapitalExists=true;
             cout<<array[i];
         }
    }
    if(!CapitalExists)
      cout<<"There are no capital letters in the array \n";

    bool lowerExists=false;

    for(int i=0; i<=N; ++i)
    {
       if(array[i]=>'a' && array[i]<='z')
         {  lowerExists=true;
             cout<<array[i];
         }
    }
    if(!lowerExists)
      cout<<"There are no lowercase letters in the array \n";


    return 0;
}
Last edited on

Those errors are simple enough to figure out... put the > before the =
That will get it to compile, but you have other problems to figure out.
Topic archived. No new replies allowed.