Computer Science Final

Pages: 12
Lines 2-5, missing semi-colons.

Line 7 you are indexing an unknown variable, did you mean to use list_vec as your vector's name?

BTW, naming your vector "list," especially since you have using namespace std; is not a good idea.

There is a C++ container, std::list. Remove std:: as you do with using namespace std; and you get name clashes you wouldn't have otherwise. This is one of the reasons why using namespace std; is considered a bad practice and should be avoided.

Your for loop would work if there were no errors.

FYI, with modern C++ (C++11) you can use an initializer list to create a vector with known values. You could create your vector like this:

2
3
   // create a vector of strings using an initalizer list
   std::vector<std::string> list_vec { "Rock", "Paper", "Scissors" };
Last edited on
Hello bethmayweather,

In addition to Furry Guy's last post the double quotes around "Rock", "Paper" and "Scissors" are slanted double quotes. The compiler does not like this. It is looking for double quotes that are vertical not slanted.

At least the compiler here did not like them.

Andy
TO THOSE WHO ARE TRYING TO HELP: Please note that the assignment calls for program fragments, not fully functional programs.

Bethmayweather, you may choose to create full programs to help debug your answers, but be sure that what you submit is only what's asked for.

Bethmayweather, regarding your solution to #2, all you need is:
1
2
3
4
for(int i = 0; i<list.size(); i++) {
      cout << list[i] << endl;
   }
}
Furry Guy's advice doesn't apply here since the assignment specifically says that the vector is called "list". Don't you just hate it when the prof requires to use bad practices??

Write a function called CalculateMortgagePayment. It should return the monthly payment. It will take in 3 parameters: the loan amount, the interest rate, and the number
of years. (Note: you only need to write the function declaration and not the logic to
calculate a monthly payment.)


1
2
3
4
5
6
double CalculateMortgagePayment(double loan_amount, double interest_rate, int years)
{
    double monthly_payment = 0;
    ...
    return monthly_payment;
}
Note: you only need to write the function declaration and not the logic to
calculate a monthly payment.

So the answer is simply
double CalculateMortgagePayment(double loan_amount, double interest_rate, int years);
Don't forget that semicolon at the end of the declaration.
Thank you all so much!!

Is this correct for #3

1
2
3
4
5
6
7
8
String word;
Int a;
While ()
{
word == quit | a != 10;

}
Is this correct for #4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
    string words;
    vector<string> v;
    cout << "Enter words" << endl;
    while (cin >> words)
    {
        v.push_back(words);
    }
    for(auto b : v)
        cout << b << "  ";
    cout << endl;
    return 0;
}
Is this correct for #5

1
2
3
4
5
6
7
8
9
10

Struct student;
{
Int first name;
Int last name;
Int Id num;
Int course names;
Int current gpa;
}
#3:
The condition for a while loop goes inside the parentheses:
while (condition) statement;
Use || for logical OR | means bit-wise OR.
You need to compare the string to "quit". Do you know howto specify a literal string like that?

#4:
I guess that will work, but it's way more complicated than what I would have written. You don't need to write a whole program and you don't need to print the words out and you don't need to read words from the user. All the question asks is that you put "hello" and "world" into the vector.

#5.
Member names can't be multiple words. In other words, "first name" is not a valid member variable name.
C++ is case sensitive, so Struct and Int should be struct and int.
You have declared first name as an int. What sort of values can be stored in it it? Are they sufficient?

Seriously, is this really the final exam for the semester? I have to say that these are "first week of class" mistakes.
Topic archived. No new replies allowed.
Pages: 12