%253Cp%253EPART%2520A.%2520Write%2520a%2520program%2520ArraysAndLoops%2520and%25
ID: 3552465 • Letter: #
Question
%253Cp%253EPART%2520A.%2520Write%2520a%2520program%2520ArraysAndLoops%2520and%2520implement%2520the%250Afollowing%2520in%2520the%2520main%2520method%253A%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E1.%2520Declare%2520an%2520array%2520arr1%2520and%2520initialize%2520it%2520to%25201%252C%25202%252C%25203%252C%25204%252C%25205%252C%25206%252C%250A7%252C%25208%252C%2520and%25209%2520%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E(For%2520the%2520rest%2520of%2520PART%2520A%252C%2520use%2520the%2520instance%2520variable%2520length%250Ainstead%2520of%2520a%2520number%2520to%2520define%2520the%2520capacity%2520of%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ethe%2520array.)%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E2.%2520Declare%2520another%2520array%2520arr2%252C%2520the%2520same%2520length%2520as%2520arr1%252C%2520without%250Agiving%2520it%2520any%2520initial%2520values.%2520%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E3.%2520Using%2520a%2520for%2520loop%2520print%2520arr1%2520displaying%2520all%2520elements%2520on%2520one%250Aline%252C%2520separated%2520by%2520a%2520comma%2520(commas%2520must%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ebe%2520placed%2520only%2520between%2520numbers).%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E4.%2520Using%2520a%2520while%2520loop%252C%2520print%2520arr2%2520displaying%2520all%2520elements%2520on%2520one%250Aline%252C%2520separated%2520by%2520a%2520dash%2520(dashes%2520must%2520be%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Eplaced%2520only%2520between%2520numbers).%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E5.%2520Using%2520a%2520for%2520loop%252C%2520copy%2520all%2520the%2520values%2520of%2520arr1%2520into%2520arr2%2520in%250Areverse%2520order.%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E6.%2520Using%2520a%2520do%252Fwhile%2520loop%252C%2520print%2520arr1%2520displaying%2520all%2520elements%2520on%250Aone%2520line%252C%2520separated%2520by%2520a%2520comma.%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E7.%2520Using%2520a%2520for%2520loop%252C%2520print%2520arr2%2520displaying%2520all%2520elements%2520on%2520one%250Aline%252C%2520separated%2520by%2520a%2520dash.%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EExpected%2520Output%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EArray%25201%253A%25201%252C2%252C3%252C4%252C5%252C6%252C7%252C8%252C9%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EArray%25202%253A%25200-0-0-0-0-0-0-0-0%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EArray%25201%253A%25201%252C2%252C3%252C4%252C5%252C6%252C7%252C8%252C9%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EArray%25202%253A%25209-8-7-6-5-4-3-2-1%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EPART%2520B.%2520Write%2520a%2520program%252C%2520Passwords%252C%2520that%2520contains%2520an%2520array%2520of%250Afive%2520names%2520and%2520another%2520array%2520of%2520five%2520passwords%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E(your%2520choice).%2520Your%2520program%2520should%2520ask%2520the%2520user%2520to%2520enter%2520a%2520name%250Aand%2520a%2520password.%2520If%2520the%2520user%2520enters%2520the%2520correct%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ename%2520with%2520its%2520related%2520password%252C%2520grant%2520access%2520(e.g.%2520display%250A%25E2%2580%259CAccess%2520granted!%25E2%2580%259D).%2520If%2520the%2520user%2520enters%2520the%2520wrong%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ename%252Fpassword%2520(can%2520be%2520either%2520or%2520both)%252C%2520allow%2520the%2520user%2520to%2520re%253Ftry%250Aonly%2520once.%2520If%2520the%2520user%2520still%2520cannot%2520enter%2520the%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ecorrect%2520name%252Fpassword%252C%2520display%2520the%2520following%253A%2520%25E2%2580%259CSorry%252C%2520your%250Ausername%252Fpassword%2520does%2520not%2520match%2520our%2520database.%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EContact%2520the%2520administrator.%25E2%2580%259D%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253EPART%2520C.%2520Write%2520a%2520program%252C%2520ArrayRange%252C%2520that%2520asks%2520the%2520user%2520to%2520input%250Aintegers%2520and%2520that%2520displays%2520the%2520difference%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ebetween%2520the%2520largest%2520and%2520the%2520smallest.%2520You%2520should%2520ask%2520the%2520user%250Athe%2520number%2520of%2520integers%2520s%252Fhe%2520would%2520like%2520to%2520enter%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253E(this%2520will%2520allow%2520you%2520to%2520set%2520the%2520length%2520of%2520the%2520array).%250A%2526nbsp%253BAllow%2520the%2520user%2520to%2520input%2520all%2520the%2520numbers%2520and%2520then%2520store%250Athem%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ein%2520the%2520array.%2520Search%2520the%2520array%2520for%2520the%2520largest%2520number%252C%2520then%250Asearch%2520for%2520the%2520smallest%252C%2520and%2520finally%2520compute%2520the%2526nbsp%253B%253C%252Fp%253E%250A%253Cp%253E%253Cbr%2520%252F%253E%253C%252Fp%253E%250A%253Cp%253Ecalculation.%2520Display%2520all%2520the%2520numbers%2520given%2520by%2520the%2520user%252C%2520the%2520max%250Anumber%252C%2520the%2520min%2520number%252C%2520and%2520the%2520difference.%253C%252Fp%253E%250AExplanation / Answer
Part A) rest part will be uploaded soon
#include <iostream>
using namespace std;
int main() {
// your code goes here
int arr1[]={1,2,3,4,5,6,7,8,9};
int arr2[]={0,0,0,0,0,0,0,0,0},i;
for( i=0;i<8;i++)
{cout<<arr1[i]<<",";
}
cout<<arr1[i];
cout<<endl;
for( i=0;i<8;i++)
{cout<<arr2[i]<<"-";
}
cout<<arr2[i];
cout<<endl;
//while loop to print element
i=0;
while(i<8)
{cout<<arr1[i]<<",";
i++;
}
cout<<arr1[i];
cout<<endl;
for(i=0;i<9;i++)
{arr2[i]=arr1[8-i];
cout<<arr2[i]<<"-";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.