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

Using c++ onr and no Write a program to load two arrays called Names and Days. L

ID: 3899446 • Letter: U

Question

Using c++

onr and no Write a program to load two arrays called Names and Days. Load the array Names with the full names of the months of the year and the array days with their corresponding days Display 10 random questions of the days of the month and check if the answer is correct or not If correct display Correct and add 10 points to his total score or display Incorrect otherwise. Display his score at the end Example RUN How many days are there in the month of March? 28 No March has 31 days How many days are there in the month of November? 30l Correcti and so on

Explanation / Answer

HI, I am providing code using random functions srand and rand as well as harcoding the questions.

Please do rate this answer positive, If i was able to help you. Let me know if you have any issues in comments

With Hardcoded questions

#include<iostream>

using namespace std;

int main() {

string Names[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

int Days[] = {31,28,31,30,31,30,31,31,30,31,30,31};

int score = 0;

int ans;

cout<<"How many days are there in month of March? ";

cin>>ans;

if(Days[2] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No March has "<<Days[2]<<" days. "<<endl;

}

cout<<"How many days are there in month of January? ";

cin>>ans;

if(Days[0] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No January has "<<Days[0]<<" days. "<<endl;

}

cout<<"How many days are there in month of April? ";

cin>>ans;

if(Days[3] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No April has "<<Days[3]<<" days. "<<endl;

}

cout<<"How many days are there in month of November? ";

cin>>ans;

if(Days[10] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No November has "<<Days[10]<<" days. "<<endl;

}

cout<<"How many days are there in month of October? ";

cin>>ans;

if(Days[9] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No October has "<<Days[9]<<" days. "<<endl;

}

cout<<"How many days are there in month of July? ";

cin>>ans;

if(Days[6] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No July has "<<Days[6]<<" days. "<<endl;

}

cout<<"How many days are there in month of May? ";

cin>>ans;

if(Days[4] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No May has "<<Days[4]<<" days. "<<endl;

}

cout<<"How many days are there in month of June? ";

cin>>ans;

if(Days[5] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No June has "<<Days[5]<<" days. "<<endl;

}

cout<<"How many days are there in month of September? ";

cin>>ans;

if(Days[8] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No September has "<<Days[8]<<" days. "<<endl;

}

cout<<"How many days are there in month of December? ";

cin>>ans;

if(Days[11] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No December has "<<Days[11]<<" days. "<<endl;

}

cout<<" Total Score: "<<score<<endl;

return 0;

}

With Random functions srand and rand

#include<iostream>

#include<cstdlib>

#include<ctime>

using namespace std;

int main() {

string Names[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

int Days[] = {31,28,31,30,31,30,31,31,30,31,30,31};

int score = 0;

int count = 0;

srand(time(NULL));

while(count != 10) {

int mon = rand()%12;

cout<<"How many days are there in month of "<<Names[mon]<<"? ";

int ans;

cin>>ans;

if(Days[mon] == ans) {

score = score + 10;

cout<<"Correct! "<<endl;

} else {

cout<<"No "<<Names[mon]<<" has "<<Days[mon]<<" days. "<<endl;

}

count++;

}

cout<<" Total Score: "<<score<<endl;

return 0;

}

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