In C++ Language:
In the following problems assume the iostream library has been included and that you are using the namespace std.
1. Define a struct for a recreational vehicle with the following members: year (int), length (float), width (float), height (float), weight (float), make (string), model (string), luxuryStyling (bool), color (string), retailPrice (float).
2. Consider the following statements. Although it may be confusing, it is legal to have name as the identifier of a one struct and separately as a member inside of the course struct.
struct name
{
string first;
string last;
};
struct course
{
char name[50];
int callNum;
int credits;
char grade;
};
struct student
{
name studentName;
int id;
course courses[10];
};
student cs_student;
student classList[100];
course cs_course;
name a_name;
Mark the following statements as valid or invalid. If a statement is invalid, explain why it your own words (compiler error messages are not acceptable).
a. name.last = "Hoa";
Answer:
b. cin >> cs_student.studentName;
Answer:
c. classList[0] = studentName;
Answer:
d. classList[1].id = 36701;
Answer:
e. a_name = classList[15].studentName;
Answer:
f. cs_student.studentName = a_name;
Answer:
g. cout << classList[10] << endl;
Answer:
h. for (int j = 0; j < 100; j++)
classList[j].studentName = a_name;
Answer:
//question 1
struct recreational_vehicle
{ int year;
float length,width,height,weight,retailPrice;
string make,model,color;
bool luxuryStyling;
};
//question 1 ends
//question 2
a. name.last = "Hoa"; is invalid
because name is struct, we can not access struct varible by struct
name
we can access using struct varible, hence, correct one is
a_name.last="Hoa";
name.last = "Hoa";
cin >> cs_student.studentName; is invalid
because cs_student.studentName is of type struct name
cin is used to taking basic input types like
int,float,double,string etc;
cin can not directly take struct name type
cin >> cs_student.studentName;
classList[0] = studentName; is invalid
because classList[0] is of type struct student
'studentName’ was not declared in this scope
studentName is of type struct name;
classList[0] = studentName;
classList[1].id = 36701; is valid;
classList[1].id is int and 36701 is int;
a_name = classList[15].studentName; is valid
a_name is type struct name
classList[15].studentName is type struct name;
cs_student.studentName = a_name; is valid
cs_student.studentName is type struct name
a_name is type struct name
cout << classList[10] << endl; is invalid
cout is used to print basic input types like
int,float,double,string etc;
cout can not directly print struct name type
for (int j = 0; j < 100; j++)
classList[j].studentName = a_name; is valid
a_name is type struct name
classList[j].studentName is type struct name;
In C++ Language: In the following problems assume the iostream library has been included and that...
Consider the following statements: struct nameType { string first; string last; }; struct courseType { string name; int callNum; int credits; char grade; }; struct studentType { nameType name; double gpa; courseType course; }; studentType student; studentType classList[100]; courseType course; nameType name; Mark the following statements as valid or invalid. If a statement is invalid, explain why. student.course.callNum = "CSC230"; cin >> student.name; classList[0] = name; classList[1].gpa = 3.45; name = classList[15].name; student.name = name; cout << classList[10] << endl;...
Answer it by using c++ context.
struct courseType struct studentType { { struct name Type { string first; string last; }; string name; int callNum; int credits; char grade; name Type name; double gpa; courseType course; }; student Type student; student Type classList[100]; course Type course; nameType name; Mark the following statements as valid or invalid. If a statement is invalid, explain why. a. student.name.last="Anderson"; b. classList[1].name = student; c. student.name = classList[10].name;
Write the functions needed to complete the following program as described in the comments. Use the input file course.txt and change the mark of student number 54812 to 80. /* File: course.cpp A student's mark in a certain course is stored as a structure (struct student as defined below) consisting of first and last name, student id and mark in the course. The functions read() and write() are defined for the structure student. Information about a course is stored as a...
IN C++ My project will be a library management system. It will have seven functions. It HAS to contain: classes, structures, pointers and inheritance. fix code according to below 1. Add a new book allows the user to enter in book name and book code Book code has to be in # “Invalid book code” “book name has been added to library” book code will be used to borrow books 2. Add a new user must use first user must...
IN C++ add Inheritance, Class and Pointers to program This is a library management program, users can borrow books and return books. Just incorporate the use of Inheritance, Class and Pointers into this program. The program should work the same after your edits. #include using namespace std; //structure to store library data struct library { int code; char title[20]; int status; }; //structure to store user data struct users { int id; char name[20]; int booksNumber; }; int main() {...
Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...
#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...
The code will not run and I get the following errors in Visual Studio. Please fix the errors. error C2079: 'inputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' cpp(32): error C2228: left of '.open' must have class/struct/union (32): note: type is 'int' ): error C2065: 'cout': undeclared identifier error C2065: 'cout': undeclared identifier error C2079: 'girlInputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' error C2440: 'initializing': cannot convert from 'const char [68]' to 'int' note: There is no context in which this conversion is possible error...
IN C++ Help to fix code Library management program. Error is when i type a letter into options menu the code breaks. after your edits, the code should still run as normal. CODE: #include<iostream> using namespace std; //structure to store library data class BookDetails{ public: struct library { int code; char title[20]; int status; }; library book_details[100]; }; //structure to store user data class UserDetails:public BookDetails{ public: struct users { int id; char name[20]; int booksNumber; }; users user_details[100]; };...
Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...