This is for a C++ program:
I'm almost done with this program, I just need to implement a bool
function that will ask the user if they want to repeat the
read_course function. I can't seem to get it right, the
instructions suggest a do.. while loop in the main function. here
is my code
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
const int SIZE = 100;
void read_name(char first[], char last[]);
void read_course(int & crn, char des[], int &
section);
bool again();
int main()
{
char user_input;
char first[SIZE];
char last[SIZE];
char des[SIZE];
int section = 0;
int crn = 0;
read_name(first, last);
do
{
read_course(crn, des, section);
cout << "Name: " << last << ",
" << first << endl;
cout << "CRN: " <<crn
<<endl<< "Destignator: " << des
<<endl;
cout << "Section: " << section
<< endl;
again();
while(again == true);
return 0;
}
void read_name(char first[], char last[])
{
cout << "Enter your first name then
press enter: " << endl;
cin.get(first, SIZE, '\n');
cin.ignore(100, '\n');
cout << "Enter your last name then
press enter: " << endl;
cin.get(last, SIZE, '\n');
cin.ignore(100, '\n');
}
void read_course(int & crn, char des[], int &
section)
{
cout << "Enter valid CRN (e.g. 123456): "
<< endl;
cin >> crn;
if(crn <= 0)
{
cout << "Please
enter a valid CRN: " << endl;
cin >> crn;
}
cin.ignore(100, '\n');
cout << "Enter Course Designator: "
<< endl;
cin.get(des, SIZE, '\n');
cin.ignore(100, '\n');
for(int i = 0;des[i]<SIZE; ++i)
{
if(des[i] == ' ')
{
cout << "Do not enter spaces. " << endl;
cout << "Enter Course Designator: " << endl;
cin.get(des, SIZE, '\n');
}
}
cout << "Enter section: " <<
endl;
cin >> section;
if(section <= 0)
{
cout << "Do not
enter a negative number, Enter section: " << endl;
cin >>
section;
}
cin.ignore(100, '\n');
}
bool again()
{
char user_input;
user_input = toupper(user_input);
cout << "Do you want to enter another
class? (Y/N): " << endl;
cin >> user_input;
if(user_input != 'Y' || user_input !=
'N')
{
cout << "Invalid
selection, Please try again." << endl << endl;
cout << "Do you
want to continue to enroll classes? (y/n): " << endl;
cin >>
user_input;
}
if(user_input == 'Y')
return true;
}
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
const int SIZE = 100;
void read_name(char first[], char last[]);
void read_course(int & crn, char des[], int &
section);
bool again();
int main()
{
char first[SIZE];
char last[SIZE];
char des[SIZE];
int section = 0;
int crn = 0;
read_name(first, last);
do
{
read_course(crn, des, section);
cout << "Name: " << last << ", " <<
first << endl;
cout << "CRN: " <<crn <<endl<<
"Destignator: " << des <<endl;
cout << "Section: " << section << endl;
}
while(again() == true); // Call again() function and compare its
return value.
return 0;
}
void read_name(char first[], char last[])
{
cout << "Enter your first name then press enter: " <<
endl;
cin.get(first, SIZE, '\n');
cin.ignore(100, '\n');
cout << "Enter your last name then press enter: " <<
endl;
cin.get(last, SIZE, '\n');
cin.ignore(100, '\n');
}
void read_course(int & crn, char des[], int &
section)
{
cout << "Enter valid CRN (e.g. 123456): " <<
endl;
cin >> crn;
if(crn <= 0)
{
cout << "Please enter a valid CRN: " << endl;
cin >> crn;
}
cin.ignore(100, '\n');
cout << "Enter Course Designator: " << endl;
cin.get(des, SIZE, '\n');
cin.ignore(100, '\n');
for(int i = 0; des[i]<SIZE; ++i)
{
if(des[i] == ' ')
{
cout << "Do not enter spaces. " << endl;
cout << "Enter Course Designator: " << endl;
cin.get(des, SIZE, '\n');
}
}
cout << "Enter section: " << endl;
cin >> section;
if(section <= 0)
{
cout << "Do not enter a negative number, Enter section: "
<< endl;
cin >> section;
}
cin.ignore(100, '\n');
}
bool again()
{
char user_input;
cout << "Do you want to enter another class? (Y/N): "
<< endl;
cin >> user_input; // Take input for user_input from
user
user_input = toupper(user_input); // Convert it to uppercase
// Validate user_input. If it's not Y or N, keep asking user to
enter a valid value
// DO this in a while loop
while(user_input != 'Y' && user_input != 'N')
{
cout << "Invalid selection, Please try again." << endl
<< endl;
cout << "Do you want to continue to enroll classes? (y/n): "
<< endl;
cin >> user_input;
user_input = toupper(user_input); // Convert it to uppercase
}
cin.ignore(100, '\n');
// If user_input is Y, return true else false
if(user_input == 'Y')
return true;
else
return false;
}
OUTPUT
This is for a C++ program: I'm almost done with this program, I just need to...
I'm getting a segmentation fault for this function, this is for a c++ program. Is there anything that you see that is obviously wrong? Am i using cin.get wrong? Please help if you can. number is my variable, and NUMBER is the const int limit void questions::addQuestion() { int i = 0; cout << "Enter the question number: " << endl; //after this line is where it seg faults cin.get(number,NUMBER, '\n'); cin.ignore(100, '\n'); cout <<...
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
Write a C++ program that uses a structure to store the following inventory information in a file: ⦁ Item description, Quantity on hand, Wholesale cost, Retail cost, and Date added to inventory. ⦁ Use a char array for item description and date. ⦁ The program should have a menu that allows the user to perform the following tasks: i. Add a new record at the end of the file. ii. Display any record in the file. iii. Change any record...
(Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the date of birth. **fall.sort(compare_DOB); //Here lies your error** #include <fstream> #include <iostream> #include <string> #include <list> #include <cctype> using namespace std; const char THIS_TERM[] = "fall.txt"; const string HEADER = "\nWhat do you want to do ?\n\n" "\t. Add a new friend name and DOB ? \n" "\t. Edit/Erase a friend record ? \n" "\t. Sort a Friend's record ? \n"...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
How can I make this compatible with older C++ compilers that DO NOT make use of stoi and to_string? //Booking system #include <iostream> #include <iomanip> #include <string> using namespace std; string welcome(); void print_seats(string flight[]); void populate_seats(); bool validate_flight(string a); bool validate_seat(string a, int b); bool validate_book(string a); void print_ticket(string passenger[], int i); string flights [5][52]; string passengers [4][250]; int main(){ string seat, flight, book = "y"; int int_flight, p = 0, j = 0; int seat_number,...
C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record { int age; string name; }; int check(record r[], int n, string nm) { for (int i = 0; i < n;...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
I have a queue and stack class program that deals with a palindrome, I need someone to help to put in templates then rerun the code. I'd greatly appreciate it. It's in C++. Here is my program: #include<iostream> #include<list> #include<iterator> #include<string> using namespace std; class Queue { public: list <char> queue; Queue() { list <char> queue; } void Push(char item) { queue.push_back(item); } char pop() { char first = queue.front(); queue.pop_front(); return first; } bool is_empty() { if(queue.empty()) { return...
I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...