Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Visual C++ homework question

Visual C++ homework question

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiontutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eugene Low
    wrote on last edited by
    #1

    // Based on the values keyed in at A, B, C, D, P, Q, // software check whether the answer at Q1, Q2, Q3 and Q4 is correct. // then software will print the 1 of following result in the list box. // "ALL CORRECT" // "Qx is wrong" // "Qx and Qy is wrong" // "Qx, Qy and Qz is wrong" // "ALL WRONG" // x,y,z should be replaced with the actual number. If only the answer for Q1 is wrong, we print "Q1 is wrong". Above is the question given and below is the code I'm doing. Can anyone tell me how to proceed or is there any mistakes in my code?

    void CPractice4Dlg::OnBnClickedBtnTest()
    {
    CString strRslt;

    UpdateData(TRUE);
    m\_listRslt.ResetContent();
    
    strRslt.Format("A = %d", m\_nA);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("B = %d", m\_nB);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("C = %d", m\_nC);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("D = %d", m\_nD);
    m\_listRslt.AddString(strRslt);
    
    strRslt.Format("P = %d", m\_nP);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("Q = %d", m\_nQ);
    m\_listRslt.AddString(strRslt);
    
    strRslt.Format("Ans Q1 = %d", m\_nAnsQ1);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("Ans Q2 = %d", m\_nAnsQ2);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("Ans Q3 = %d", m\_nAnsQ3);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("Ans Q4 = %d", m\_nAnsQ4);
    m\_listRslt.AddString(strRslt);
    
    int arrA\[4\] = {m\_nAnsQ1, m\_nAnsQ2, m\_nAnsQ3, m\_nAnsQ4};
    int Q1 = m\_nA && m\_nB;
    int Q2 = m\_nC || m\_nD;
    int Q3 = m\_nC >> m\_nP;
    int Q4 = m\_nD << m\_nQ;
    int arrB\[4\] = {Q1, Q2, Q3, Q4};
    
    strRslt.Format("%d", Q1);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("%d", Q2);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("%d", Q3);
    m\_listRslt.AddString(strRslt);
    strRslt.Format("%d", Q4);
    m\_listRslt.AddString(strRslt);
    
    int count = 0;
    for(int i=0; i<4; i++){
    	if(arrA\[i\] == arrB\[i\]){
    		count++ ;
    	}
    }
    bool found = false;
    for(int i=0; i<4; i++){
    	for(int j=0; j<4; j++){
    		if(arrA\[i\] == arrB\[i\]){
    		count++ ;
    		}
    		 else if(!found && j==3){
    			strRslt.Format("Q%d is wrong", i+1);
    			m\_listRslt.AddString(strRslt);
    		}
    	}
    }found = false;
    
    if(count == 4){
    	strRslt.Format("ALL CORRECT");
    	m\_listRslt.AddString(strRslt);
    }
    

    }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups