Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Help writing C++ Loop: I\'m given the following list in a vector: X 1 2 X 3

ID: 3693442 • Letter: N

Question

Need Help writing C++ Loop:

I'm given the following list in a vector:

X
1
2
X
3
4
X
5
6

I have to use "isdigit" or "isalpha" to check each entry. If the entry is an alphabet, I have to add the digits following that into functions 1,2,3. So, when the code sees that first X, it has to add 1 and 2 into "function1(a,b)". Next, when it sees the second X, it has to add 3 and 4 into "function2(a,b)". Next, when the code sees the third X, it has to add 5 and 6 into "function3(a,b)". This code should be written in pseudo code. Can someone help me write this loop? I am very confused.

Explanation / Answer

xc = 0, nc = 0, a = 0, b = 0;

for each x in list:

if(x isalpha) {

xc = xc + 1;

nc = nc + 1;

continue;

}

if(x isdigit) {

if(nc == 1){
a = x;
nc = nc + 1;
continue;
}


if(nc == 2){
b = x;
nc = 0;
}

if(xc == 1 && nc == 0){
call function1(a,b)
}

if(xc == 2 && nc == 0){
call function2(a,b)
}

if(xc == 3 && nc == 0){
call function3(a,b)
}
}


  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote