Question

Hello I am taking an Introduction to Programming class and I need help coming up with...

Hello I am taking an Introduction to Programming class and I need help coming up with a Psuedocode for an algorithm. Here is the assignment:

1. Use an array to prompt the user to enter a credit card account number

2. Use the sequential search algorithm to locate the credit card number entered by the user

3. If the credit card number is NOT in the array, display a message indicating the number is invalid

4. If the credit card number is in the array, display a message indicating the credit card number is valid

Create a psuedocode based on the programs needs.

Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
//method to search element s in array a
//if found it return its index
//other wise -1
int sequential_search(int a[],int n,int s)
{
int i=0;
while(i<n)
{
  if(a[i]==s)return i;//returning index
i++;
}
return -1;//if not found
}

int main()
{
int n;//reading input...
cout<<"Enter how many details you want to enter:";
cin>>n;

int credit_cards[n];
cout<<"Enter "<<n<<" credit card numbers:";
int i=0;
while(i<n)
{
  cin>>credit_cards[i];
  i++;
}

int s;
cout<<"Enter element to search:";
cin>>s;
int l=sequential_search(credit_cards,n,s);
if(l!=-1)
{
  cout<<"Valid.."<<endl;
}
else cout<<"Not valid\n";


}

output:

Enter how many details you want to enter:3
Enter 3 credit card numbers:123 432 129
Enter element to search:432
Valid..


Process exited normally.
Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
Hello I am taking an Introduction to Programming class and I need help coming up with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, I have been working all night on a flowchart for school : Design a program...

    Hello, I have been working all night on a flowchart for school : Design a program using Flowgorithm or any flowcharting software that asks the user to enter a store's sales for each day of the week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week and display the result. Those are the instructions, this will be due tonight and I was hoping to fix it, I am just having...

  • I am a college student taking an INTRODUCTORY Windows 10 Operating System SCRIPTING course and need...

    I am a college student taking an INTRODUCTORY Windows 10 Operating System SCRIPTING course and need some help with the batch file I am creating for a homework assisgnment.   I created the menu below and need some help with option A Please choose a task from the list below A) Add a new user account I need to use SET /P to prompt for a login name and if the user already exists display a message and return to the...

  • I am a college student taking an INTRODUCTORY Windows 10 operating system SCRIPTING course and need...

    I am a college student taking an INTRODUCTORY Windows 10 operating system SCRIPTING course and need some help with creating this batch script.   I need to create the below menu: Please choose a task from the list below A) Add a new user account I need to use the SET /P command to add a new user and prompt for a login name. Check if the user already exists and if so display an appropriate message and return to the...

  • Hello. can anyone solve this. i am having hard time with this. please post a solution...

    Hello. can anyone solve this. i am having hard time with this. please post a solution ASAP a) Create a class named Student. Data fields for Student class include an integer Student ID, a String name, and a double CGPA. Methods include a constructor that requires values for all data fields, as well as get and set methods for each of the data fields. b) Create an application that allows a user to enter values for an array of 15...

  • I am a college student taking an intro to linux shell programming course and need some...

    I am a college student taking an intro to linux shell programming course and need some help with this question. I need to write an until statement as indicated: Check to see if the file cis132 exists in the current directory. If it does not a message will be printed every 10 seconds indicating that file does not exist. Once the file is created the message will stop. Thanks for your help.

  • I am a college student and need some help with this homework problem. I am taking...

    I am a college student and need some help with this homework problem. I am taking an introductory Operating Scripting course (windows 10) I need to create a batch file named UserInfolog.bat.   Instead of displaying the output to the screen, redirect all output to a file named computername.log and it must be created each time the batch file is executed.   After redirecting the output to the log file, the batch file must display that file's contents in the command prompt...

  • I need help with this question for programming. The language we use is C++ The program...

    I need help with this question for programming. The language we use is C++ The program should ask the user if they want to search for a boy or girl name. It should then ask for the name search the appropriate array for the name and display a message saying what ranking that name received, if any. The name files (BoyNames.txt and GirlNames.txt) are in order from most popular to least popular and each file contains two hundred names. The...

  • Need some help I am not understanding this programming class at all. We are using Microsoft...

    Need some help I am not understanding this programming class at all. We are using Microsoft visual studio with python in console mode to complete these labs. Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT